Jump to content

form submission re-direct problem


gskurski

Recommended Posts

I'm having a problem which I'm sure will take a simple fix, but I can't seem to figure it out. I have a form now that lets you pick from six different options and then submit it to a redirect php file. In the php file I have an if, else if statement that is suppose to redirect to different pages corresponding to the original value selected in the form. Here is my code.

 

 

<form action="subredirect.php" method="post" target="index">

<select name="redirect">

<option value="vodka">Vodkas</option>

<option value="bourbons">Bourbons</option>

<option value="rum">Rums</option>

<option value="gin">Gins</option>

<option value="brandy">Brandy</option>

<option value="tequila">Tequila</option>

<option value="whiskey">Whiskey</option>

</select>

<input type="submit" value="Go!">

</form>

 

And here is my php file

<?php

if ($_POST(['redirect'])== "vodka"){
   header("Location: http://www.website.com/vodkasubmit.php");
   exit ();
}

elseif ($_POST(['redirect'])== "bourbon"){
   header("Location: http://www.website.com/bourbonsubmit.php");
   exit ();
}
elseif ($_POST(['redirect'])== "rum"){
   header("_POST(['redirect']): http://www.website.com/rumsubmit.php");
   exit ();
}
elseif ($_POST(['redirect'])== "gins"){
   header("Location: http://www.website.com/ginsubmit.php");
   exit ();
}
elseif ($_POST(['redirect'])== "brandy"){
   header("Location: http://www.website.com/brandysubmit.php");
   exit ();
}
elseif ($_POST(['redirect'])== "tequila"){
   header("Location: http://www.website.com/tequilasubmit.php");
   exit ();
}
elseif ($_POST(['redirect'])== "whiskey"){  
   header("Location: http://www.website.com/whiskeysubmit.php");
   exit ();
}
?>

Any help is really appreciated!

 

Thanks

 

-Gerry

Link to comment
https://forums.phpfreaks.com/topic/202181-form-submission-re-direct-problem/
Share on other sites

Try this:

<?php

if (isset($_POST['redirect'])){
header("Location: http://www.website.com/".$_POST['redirect']."submit.php");
exit();
}

?>


<form method="post" action="">
<select name="redirect">
	<option value="vodka">Vodkas</option>
	<option value="bourbons">Bourbons</option>
	<option value="rum">Rums</option>
	<option value="gin">Gins</option>
	<option value="brandy">Brandy</option>
	<option value="tequila">Tequila</option>
	<option value="whiskey">Whiskey</option>
</select>
<input type="submit" value="Go!">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.