KevinM1 Posted July 2, 2007 Share Posted July 2, 2007 Without using JavaScript, is it possible to have a form with two actions? I'm thinking no, but would like confirmation. Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/ Share on other sites More sharing options...
Dragen Posted July 2, 2007 Share Posted July 2, 2007 yes. If you have two submit buttons with different names. <input type="submit" name="action1" value="submit something"> <input type="submit" name="action2" value="submit something else"> then on the page you're submitting two have something like: if(isset($_POST['action1'])){ //do something }elseif(isset($_POST['action2'])){ //do something else } Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287918 Share on other sites More sharing options...
KevinM1 Posted July 2, 2007 Author Share Posted July 2, 2007 yes. If you have two submit buttons with different names. <input type="submit" name="action1" value="submit something"> <input type="submit" name="action2" value="submit something else"> then on the page you're submitting two have something like: if(isset($_POST['action1'])){ //do something }elseif(isset($_POST['action2'])){ //do something else } True, but I was thinking more along the lines of: <?php if(isset($_POST['submit1'])){ //use <form action='$_SERVER['PHP_SELF']'> } else if(isset($_POST['submit2'])){ //use <form action='formhandler.php'> } ?> Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287955 Share on other sites More sharing options...
Dragen Posted July 2, 2007 Share Posted July 2, 2007 you can't change the form action after it's been submitted. try something like this: <?php if(isset($_POST['submit1'])){ //action code on this page }elseif(isset($_POST['submit2'])){ //re-direct to other page require('formhandler.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287963 Share on other sites More sharing options...
KevinM1 Posted July 2, 2007 Author Share Posted July 2, 2007 you can't change the form action after it's been submitted. try something like this: <?php if(isset($_POST['submit1'])){ //action code on this page }elseif(isset($_POST['submit2'])){ //re-direct to other page require('formhandler.php'); } ?> Yeah, I figured as much. It's unfortunate, as I was hoping to use the post method rather than get, but oh well. Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287971 Share on other sites More sharing options...
Dragen Posted July 2, 2007 Share Posted July 2, 2007 the code I've supplied will work fine and it's using post, not get. Just set the form action to $_SERVER['PHP_SELF']. The at the top of the page have a small statement checking if the form has been submitted. If it has it checks whether to include another page or echo the form. When you use require() the required page will be able to read any post variables, so it will still work for you. I use this method a lot on my sites. Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287976 Share on other sites More sharing options...
KevinM1 Posted July 2, 2007 Author Share Posted July 2, 2007 the code I've supplied will work fine and it's using post, not get. Just set the form action to $_SERVER['PHP_SELF']. The at the top of the page have a small statement checking if the form has been submitted. If it has it checks whether to include another page or echo the form. When you use require() the required page will be able to read any post variables, so it will still work for you. I use this method a lot on my sites. OH, okay. Nice. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/58069-solved-form-actions/#findComment-287983 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.