Tutorial
Click on thumbnailed images to enlarge
It works like the usual drop down menu only difference is, it's written in PHP.
First step, design the drop down form element using PHP...
<?php
# These are the files we intend to target using an array named $dynsource
$dynsource = array(
"Homepage" => "index.html",
"Download" => "download.html",
"Contact" => "contact.php"
);
# The form design starts here! echo is the same as document.write in javascript
echo "<form action=\"goto.php\" method=\"get\">";
echo "<select name=\"phpnavigation\" class=\"allselint\" size=\"1\">";
# Then, we have the foreach() loop to fetch everything the $dynsource array and list each of them as options of select. Note also, the value of the targeted indexes are assigned as $dynsourceVALUE and the display as $dynsourceKEY.
foreach($dynsource as $dynsourceKEY => $dynsourceVALUE){
echo "<option value=\"$dynsourceVALUE\">$dynsourceKEY</option>";
}
echo "</select>"
. "<br /><br /><input class=\"allbttint\" type=\"submit\" value=\"read\" />"
. "</form>";
?>
Second, the processor file. Notice in the form, we set the action as "goto.php". So, name the processor file as, "goto.php".
<?php
# This is a standard URL fetching method using PHP, the $_REQUEST (assigned with the SELECT NAME "phpnavigation"
$DDget = $_REQUEST["phpnavigation"];
# The fetched URL then assigns the targeted value of the index. You'll notice after submitting the form the URL is written as e.g: http://yourdomain.com/goto.php?phpnavigation=index.html
# header() function is standard, and it redirects your page like the normal HTML META tag. Location is the parameter and $DDget is the variable of the fetch variable $_REQUEST
header("Location: $DDget");
?>
Easy no?
First step, design the drop down form element using PHP...
<?php
# These are the files we intend to target using an array named $dynsource
$dynsource = array(
"Homepage" => "index.html",
"Download" => "download.html",
"Contact" => "contact.php"
);
# The form design starts here! echo is the same as document.write in javascript
echo "<form action=\"goto.php\" method=\"get\">";
echo "<select name=\"phpnavigation\" class=\"allselint\" size=\"1\">";
# Then, we have the foreach() loop to fetch everything the $dynsource array and list each of them as options of select. Note also, the value of the targeted indexes are assigned as $dynsourceVALUE and the display as $dynsourceKEY.
foreach($dynsource as $dynsourceKEY => $dynsourceVALUE){
echo "<option value=\"$dynsourceVALUE\">$dynsourceKEY</option>";
}
echo "</select>"
. "<br /><br /><input class=\"allbttint\" type=\"submit\" value=\"read\" />"
. "</form>";
?>
Second, the processor file. Notice in the form, we set the action as "goto.php". So, name the processor file as, "goto.php".
<?php
# This is a standard URL fetching method using PHP, the $_REQUEST (assigned with the SELECT NAME "phpnavigation"
$DDget = $_REQUEST["phpnavigation"];
# The fetched URL then assigns the targeted value of the index. You'll notice after submitting the form the URL is written as e.g: http://yourdomain.com/goto.php?phpnavigation=index.html
# header() function is standard, and it redirects your page like the normal HTML META tag. Location is the parameter and $DDget is the variable of the fetch variable $_REQUEST
header("Location: $DDget");
?>
Easy no?
Tutorial Comments
No comments yet. Be the first one to comment!