View Full Version : php
rite i want 2 make a drop down menu with a go button!
so wen the menu drops down u choose the link then press go!
i can not use java script so can any1 help m?
Not sure if you just wanted the html part of the code or both so i made both.
First the html(the link_me.htm page):
<form method="POST" action="go_action.php">
<select name="addr">
<option value="none">----Please choose a location----</option>
<option value="0">Majorgeeks forums</option>
<option value="1">Google.com search</option>
</select>
<input type="submit" value="GO" />
</form>
Then two ways of redirecting the user, the first redirects the user instantly while the other does so in 5 seconds.
go_action.php file:
<?php
//the array of sites
$sites = array("http://forum.majorgeeks.com/index.php", "http://www.google.com/");
//count the number of sites in array(for validation)
$max = count($sites);
//decrease the number because the array keys always start at 0
$max--;
//check if the values are valid
if($_POST['addr'] >= 0 && $_POST['addr'] <= $max && $_POST['addr'] != "none")
{
//if the values are valid redirect the user
header("location: ".$sites[$_POST['addr']]);
}
else
{
//if the values were not valid send the user back to the selection page
header("location: link_me.htm");
}
?>
Or:
<?php
//the array of sites
$sites = array("http://forum.majorgeeks.com/index.php", "http://www.google.com/");
//count the number of sites in array(for validation)
$max = count($sites);
//decrease the number because the array keys always start at 0
$max--;
//check if the values are valid
if($_POST['addr'] >= 0 && $_POST['addr'] <= $max && $_POST['addr'] != "none")
{
//if they were valid output the html
echo"<head>\n";
echo"<meta http-equiv=\"Refresh\" content=\"5;url=".$sites[$_POST['addr']]."\" />\n";
echo"<title>Redirected to site: ".$sites[$_POST['addr']]."</title>\n";
echo"</head>\n";
echo"<body>\n";
echo"<center>You will be redirected to the site ".$sites[$_POST['addr']]." in 5 seconds.<br />\n";
echo"If not, please click this link: <a href=\"".$sites[$_POST['addr']]."\">".$sites[$_POST['addr']]."</a></center>\n";
echo"</body>\n";
}
else
{
//if the values were not valid send the user back to the selection page
header("location: link_me.htm");
}
?>
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.