Forum Moderators: coopster
I use php in the most basic of ways and I have now come up against a hurdle.
I have an html form from which visitors can select a country from a list. Each country is assigned a value:
<form action="http://www.example.com/world.php" ...
<option value="1"> USA </option>
<option value="2"> Brasil </option>, etc.
In the world.php I want the php code to redirect the browser to open that country's website.
Should I assign the country's URL to the value, should the url be in the world.php file? Help.
Can someone suggest a way of doing this.
Thank you,
Here is a sample code I just wrote that could be used for world.php to perform as specified.
-----------------------------------------------
$country_urls = array('-','usa site','brazil site',...); // The "-" in the first slot is since there's no 0 value in the options
$form_method = 0; // 0 for POST, 1 for GET
$form_value = "country"; // change to name of <SELECT>
// STORE COUNTRY NUMERICAL VALUE IN $c_code
if ($form_method == 0)
$c_code = $_POST[$form_value];
else
$c_code = $_GET[$form_value];
//GET LOCATION IN VARIABLE
$loc = $country_urls[$c_code];
//SEND OFF
@header("Location:$loc");
-----------------------------------------------
I have implemented your code. I get what you are doing.
Unfortunatly, once I select the country, the browser returns a blank screen.
When I press submit, the url goes to: http://www.example.com/world.php?country=1&Submit=Go
and the screen is blank.
the Form code:
<form name="form1" method="get" action="http://www.example.com/world.php">
<select name="country">
<option value="1">USA</option>
<option value="2">Brasil</option>
<option value="3">Mexico</option>
</select>
<input type="submit" name="Submit" value="Go" />
The world.php code:
<?php
$country_urls = array('-','www.exampleusa.com','http://www.example.com.br','http://www.example.com.mx'); // The "-" in the first slot is since there's no 0 value in the options
$form_method = 0; // 0 for POST, 1 for GET
$form_value = "country"; // change to name of <SELECT>
// STORE COUNTRY NUMERICAL VALUE IN $c_code
if ($form_method == 0)
$c_code = $_POST[$form_value];
else
$c_code = $_GET[$form_value];
//GET LOCATION IN VARIABLE
$loc = $country_urls[$c_code];
//SEND OFF
@header("Location:$loc");
?>
Anything out of place?
Thank you,