Jump to content

Form with multiple submit buttons


Ender22

Recommended Posts

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?

Link to comment
Share on other sites

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
     }

}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.