我有一个正在使用的插件,它使用数组创建美国各州的下拉列表,然后使用循环填充选择框。这是数组
//Define the US State Array to be used to generate the STATE select box
$usStates = array(
"AL" => "Alabama",
"AK" => "Alaska",
"AZ" => "Arizona",
"AR" => "Arkansas",
"CA" => "California",
"CO" => "Colorado",
"CT" => "Connecticut",
"DE" => "Delaware",
"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",
"NV" => "Nevada",
"NH" => "New Hampshire",
"NJ" => "New Jersey",
"NM" => "New Mexico",
"NY" => "New York",
"NC" => "North Carolina",
"ND" => "North Dakota",
"OH" => "Ohio",
"OK" => "Oklahoma",
"OR" => "Oregon",
"PA" => "Pennsylvania",
"RI" => "Rhode Island",
"SC" => "South Carolina",
"SD" => "South Dakota",
"TN" => "Tennessee",
"TX" => "Texas",
"UT" => "Utah",
"VT" => "Vermont",
"VA" => "Virginia",
"WA" => "Washington",
"WV" => "West Virginia",
"WI" => "Wisconsin",
"WY" => "Wyoming"
);
和循环...
//Loop through the state array to build the state select box
foreach( $usStates as $key => $value ) {
$selected = "";
if($_POST['orderState'] == $key) $selected = "selected";
$wpgft_post_content .= '<option value="'.$key.'" ' . $selected . '>'. $value .'</option>';
}
$wpgft_post_content .='</select>';
if($error_state) $wpgft_post_content .='<br /><span class="wpgft_error">'.$error_state.'</span></dd>';
} else {
$wpgft_post_content .='<dt>State / Province / Region:</dt>';
$wpgft_post_content .= '<select name="orderState"'.$ro.'>';
如果我需要将科罗拉多州设置为默认州,我应该在哪里/如何做到这一点?