Forms
|
|
|
|
<?php //FUNCTION TO GENERATE OPTION FROM ARRAY
//
//The $options variable is an array where the key is the value
//of the option and the value is the displayed part of the option.
//
//The $selected variable is the item you want preselected and must
//match the value.
//
//The $var is the name of the option which will also be your
//variable in the script that uses your form data.
//
//Randall Augustus Alexander
//zonezero@zonedzero.net
//http://www.zonedzero.net ,.com, .org
function make_option($options, $selected = "", $var)
{
echo "<SELECT NAME='$var'>n";
while (list ($value, $display) = each ($options))
{
echo "<OPTION VALUE='$value' ";
if ($value == $selected){$select = "SELECTED";}
else {$select = "";}
echo " $select>$display</OPTION>n";
}
echo "</SELECT>n";
}?>
|
|
|
Usage Example
|
<?php //PREPARE ARRAYS $options_gender = array("m"=>"Male", "f"=>"Female");
//SETUP HTML AND GENERATE OPTION CODE echo "<html>
<head>
<title>Your Title</title>
</head>";
echo "<FORM ACTION='action.php' METHOD='post'>n";
make_option($options_gender, Female, gender);
echo "<p></p><INPUT TYPE='Submit' NAME='Submit'>n";
echo "<p>$selected - $var n";
echo "</html>"; ?>
|
|
|
Rate This Script
|
|
|
|