verdrm Posted March 21, 2008 Share Posted March 21, 2008 I have two submit buttons with different names, and I want the form to post differently for each. For example: - Submit button 'Submit1' should post form values to insert.php - Submit button 'Submit2' should post form values to insert2.php How do I do this? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/ Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 the properly to allow 1 form to handle 2 unique processes is to use a radio button that controls the process not multiple submit buttons. then use a switch on it i.e <input type="radio" name="action" value="insert1" /> <input type="radio" name="action" value="insert2" /> On process page <?php switch ($_POST['action']){ case "insert1": #Do insert type 1 break; case "insert2": #Do insert type 2 break; default: #Output error } ?> Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497804 Share on other sites More sharing options...
phpretard Posted March 21, 2008 Share Posted March 21, 2008 if (isset($_POST['submit1'])){$result = mysql_query("INSERT INTO ...1");} if (isset($_POST['submit2'])){$result = mysql_query("INSERT INTO ...2");} Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497805 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 What is the form action I need to use cooldude832? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497873 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 what do u mean form action? You dont' need to do much just have 1 submit button and add in a radio section similar to what I shown. Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497875 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 That doesn't work for me; are you sure that code is correct? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497900 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 I didn't give you an exact "code" I gave you an example on how to do it Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497918 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 I need to submit the form in two different ways...(i.e.) one way needs to go to insert.php and another needs to go to insert2.php. Can you provide a code that will do that? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497924 Share on other sites More sharing options...
thomashw Posted March 21, 2008 Share Posted March 21, 2008 Do you mean you need it to go to two different pages simultaneously, or one of two pages depending on what a user selects? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497929 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 One of two pages depending on what the user selects. Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497933 Share on other sites More sharing options...
thomashw Posted March 21, 2008 Share Posted March 21, 2008 Okay. For the switch statement above he's saying put the code for BOTH pages on one submit page and have the form submit to this page. Then for each case you'd have the code depending on which they selected. Does that make sense? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497940 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 It makes sense but it doesn't work. Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497942 Share on other sites More sharing options...
thomashw Posted March 21, 2008 Share Posted March 21, 2008 Can you post the code you made using the switch statement? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497944 Share on other sites More sharing options...
verdrm Posted March 21, 2008 Author Share Posted March 21, 2008 <?php switch ($_POST['action']){ case "insert1": $r = $_GET['id']; header("Location:insert.php?id=$r&s=1"); break; case "insert2": $r = $_GET['id']; header("Location:insert.php?id=$r&s=0"); break; } ?> What I need this code to do is SUBMIT the page to either insert.php with s=1 or s=0 OR it could be to two separate pages. Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497945 Share on other sites More sharing options...
thomashw Posted March 21, 2008 Share Posted March 21, 2008 Put the switch statement on the submitted page. So your page with the form would look like this: <form action="submit.php" ....> <input type="radio" name="action" value="1"...> <input type="radio" name="action" value="2"...> and then on submit.php: switch ($_POST['action']) { case "1": // The page for case "1". break; case "2": // The page for case "2". break; default: // Put an error line here. } Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497954 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 what I am saying is you don't need to make 2 processor pages combine them into 1 page and the switch handles th alternative tasking of it. Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497962 Share on other sites More sharing options...
Barand Posted March 21, 2008 Share Posted March 21, 2008 Give both submit buttons the same name but different values <input type='submit' name='sub' value='A'> <input type='submit' name='sub' value='B'> then <?php switch ($_POST['sub']) { case 'A': // do something break; case 'B': // do something else break; } ?> Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497964 Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 For a strict doc I thought that a form can have 0-1 inputs defined the type of "submit"? Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497967 Share on other sites More sharing options...
Barand Posted March 22, 2008 Share Posted March 22, 2008 try it <?php if (isset ($_POST['sub'])) { switch ($_POST['sub']) { case 'A': echo 'you clicked A'; break; case 'B': echo 'you clicked B'; break; } } ?> <form method='post'> <input type='submit' name='sub' value='A'> <input type='submit' name='sub' value='B'> </form> Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497976 Share on other sites More sharing options...
cooldude832 Posted March 22, 2008 Share Posted March 22, 2008 this was strict valid which I thought it wasn't <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Test</title> </head> <body> <form method='post' action=""> <div> <input type='submit' name='sub' value='A' /> <input type='submit' name='sub' value='B' /> </div> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/97279-multiple-submit-actions/#findComment-497980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.