Ender22 Posted October 14, 2007 Share Posted October 14, 2007 Hey guys, Ive been trying to figure something out for a bit and im a little stuck on it. I have a page with a form that on-submission passes the values of 2 hidden fields to the next page. Now however, I want to give the user a choice between 2 pages to go to, but im having trouble finding a way to pass the hidden fields to either of the 2 pages. Right now im trying to use 2 submit buttons to do this, each one linkining to one of the 2 possible pages. Then I use the code: if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "insertGuide")) { if (isset($_POST['Link'])) { $insertGoTo = "AddLink.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } else if (isset($_POST['Upload'])) { $insertGoTo = "AddUpload.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } } to check which submit button the user has pressed. This works fine for allowing the user to choose which page to go to, however the hidden field data that used to get passed no longer gets sent. I think because my form is not directly linking to the new pages, when the form is submitted it simply comes back to the current page, and the hidden field data does not get sent after the header command is called. There must be a better way to do this, because it seems like a fairly common thing that may need to be done. Can anyone help me out with this? Quote Link to comment https://forums.phpfreaks.com/topic/73218-form-with-multiple-submit-buttons/ Share on other sites More sharing options...
Barand Posted October 14, 2007 Share Posted October 14, 2007 When using multiple submit buttons, give the the same name (eg name='sub') but different values if (isset($_POST['sub'])) { if ($_POST['sub'] == 'Link') { // link stuff } elseif ($_POST['sub'] == 'Upload') { // upload stuff } } Quote Link to comment https://forums.phpfreaks.com/topic/73218-form-with-multiple-submit-buttons/#findComment-369393 Share on other sites More sharing options...
Ender22 Posted October 14, 2007 Author Share Posted October 14, 2007 Thanks for the post. Yep that makes the submit buttons link to the correct page, however it doesnt solve the problem of my hidden form variables not being sent to the new pages. Back when I only linked to a single page, I had my form action=AddLink.php which linked me to the correct page, and passed the form variables. But now when I navigate to the new pages using the headers command (because I cant use the form action thing to link to different pages) the hidden form variables are no longer sent. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/73218-form-with-multiple-submit-buttons/#findComment-369422 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.