trp Posted April 15, 2010 Share Posted April 15, 2010 Hey, I am using some forms that post things to the URL (such as &update) for me to use within an 'if isset' statement. The thing is I have one page with more than one form, each with different outputs, the first one adds to the url and any action after that also involves running the first request again. Does anyone know a resolution for this? Thanks, TRP Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 15, 2010 Share Posted April 15, 2010 Different submit button names? Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 15, 2010 Share Posted April 15, 2010 Give the various submit buttons meaningful names then check for the name just as you would with a submit button named 'submit'. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
trp Posted April 16, 2010 Author Share Posted April 16, 2010 I'll show you the code echo "<tr>"; echo "<td align=center colspan=2> <form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actionone\"> <input type=\"submit\" value = \"$actionone\"> </form> </td> <td></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=center colspan=2> <form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actiontwo\"> <input type=\"submit\" value = \"$actiontwo\"> </form> </td> <td></td>"; echo "</tr>"; echo "<tr>"; echo "<td align=center colspan=2> <form method=\"post\" action=\"{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}&$actionthree\"> <input type=\"submit\" value = \"$actionthree\"> </form> </td> <td></td>"; echo "</tr>"; Then picked up by annother query using if isset, but as the url can easily look like &whatever&something it will do both.. Quote Link to comment Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 name your submit buttons <input type="submit" name="submit_form" value="submit1"/> <input type="submit" name="submit_form" value="submit2"/> <input type="submit" name="submit_form" value="submit3"/> and in the code that checks if a form submitted if(isset($_POST['submit_form'])){ switch($_POST['submit_form']){ case "submit1": // Do something when submit button 1 is pressed break; case "submit2": // Do something when submit button 2 is pressed break; case "submit3": // Do something when submit button 3 is pressed break; } } Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 Or you could do it the way that most likely you'll have. <input type="submit" name="submit_form1" value="submit"/> <input type="submit" name="submit_form2" value="submit"/> <input type="submit" name="submit_form3" value="submit"/> Notice how I changed the names of the button, instead of value as deanlearner. Then to validate the forms.. <?php if(isset($_POST['submit_form1'])) { //Content for form 1 will go here... } if(isset($_POST['submit_form2'])) { //Content for form 2 will go here... } if(isset($_POST['submit_form3'])) { //Content for form 3 will go here... } And so on. I don't like using switches when using multiple forms. I like it all grouped together. Quote Link to comment Share on other sites More sharing options...
trp Posted April 17, 2010 Author Share Posted April 17, 2010 Cheers guys, thats really helpful, works a treat too Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.