Jump to content

[SOLVED] Pass variable to URL from form list


giraffemedia

Recommended Posts

Hi

 

is it possible to send a variable to a URL from a form list by using the action?

 

What I want to do is select a value from a menu/list and print that as a variable in the URL on the resulting page.

 

Here is some test code...

 


<?

$issue = $_POST['search'];

?>
<form action="/test/search.php?search_by=<? echo $issue; ?>" method="post">
<select name="search" id="search">
	<option value="">No.</option>
	<option value="">---</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
       </select>						
<input type="submit" name="button" id="tools_button" value="Go" />
</form>

?>

 

Is this close or is there a different way to achieve this?

 

Thanks for looking.

 

James

You need a script to process the form first. Try this:

<?
if(isset($_POST['button']) && $_POST['button'] == "Go")
{
  header("Location:/test/search.php?search_by=".$_POST['search'];
} else {
?>
<form action="" method="post">
<select name="search" id="search">
	<option value="">No.</option>
	<option value="">---</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
       </select>						
<input type="submit" name="button" id="tools_button" 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.