Location: PHPKode > scripts > plato > plato/plato.stateSel.php
<?php
/*
	Function stateSel() will create a state select box
	// --Recognized Vars
	// var[name] = select name
	// var[output] = short or full - length of
	// var[selected] = the selected index
	// --Additional Vars
	// any other vars passed will be added to the select tag
	// example: var[class] = input
	// 		<select name="selectname" class="input">...
*/
function _stateSel($vars = array())
{
	$stateArray = array("AL" => "Alabama", "AK" => "Alaska", "AZ" => "Arizona", "AR" => "Arkansas", "CA" => "California", "CO" => "Colorado", "CT" => "Connecticut", "DE" => "Delaware", "DC" => "District of Columbia", "FL" => "Florida", "GA" => "Georgia", "HI" => "Hawaii", "ID" => "Idaho", "IL" => "Illinois", "IN" => "Indiana", "IA" => "Iowa", "KS" => "Kansas", "KY" => "Kentucky", "LA" => "Louisiana", "ME" => "Maine", "MD" => "Maryland", "MA" => "Massachusetts", "MI" => "Michigan", "MN" => "Minnesota", "MS" => "Mississippi", "MO" => "Missouri", "MT" => "Montana", "NE" => "Nebraska", "ND" => "North Dakota", "OH" => "Ohio", "OK" => "Oklahoma", "OR" => "Oregon", "PA" => "Pennsylvania", "PR" => "Puerto Rico", "RI" => "Rhode Island", "SA" => "South America", "NV" => "Nevada", "NH" => "New Hampshire", "NJ" => "New Jersey", "NM" => "New Mexico", "NY" => "New York", "NC" => "North Carolina", "SC" => "South Carolina", "SD" => "South Dakota", "TN" => "Tennessee", "TX" => "Texas", "UT" => "Utah", "VT" => "Vermont", "WV" => "West Virginia", "WI" => "Wisconsin", "WY" => "Wyoming", "VA" => "Virginia", "WA" => "Washington");
	
	strlen($vars["name"]) > 0 ? $name = $vars["name"] : $name = "stateSel";
	strlen($vars["output"]) > 0 ? $output = $vars["output"] : $output = "short";
	strlen($vars["selected"]) > 0 ? $selected = $vars["selected"] : $selected = "";
	
	$i = 0;
	$keys = array_keys($vars);
	for ($j = 0; $j < count($keys); $j++){
		if (($keys[$j] != "name") && ($keys[$j] != "output") && ($keys[$j] != "selected")){
			$varKey[$i] = $keys[$j];
			}
		}
	if (count($varKey) > 0){
		for ($j = 0; $j < count($varKey); $j++){
			$selectStr = sprintf(" %s=\"%s\"", $varKey[$j], $vars[$varKey[$j]]);
			}
		}
	
	$sel = sprintf("<select name=\"%s\"%s>\n", $name, $selectStr);
	
	for ($i = 0; $i < count($stateArray); $i++){
		$key = key($stateArray);
		$val = $stateArray[$key];
		
		if ($output == "short"){
			$selected == $key ? $sel .= sprintf("<option value=\"%s\" selected=\"selected\">%s</option>\n", $key, $key) : $sel .= sprintf("<option value=\"%s\">%s</option>\n", $key, $key);
			} else {
			$selected == $key ? $sel .= sprintf("<option value=\"%s\" selected=\"selected\">%s</option>\n", $key, $val) : $sel .= sprintf("<option value=\"%s\">%s</option>\n", $key, $val);
			}
		
		next($stateArray);
		}
	
	$sel .= sprintf("</select>");
	
	return $sel;
}
?>
Return current item: plato