-
-
Save aosmichenko/8abc76bd9d5fe5f45edc97fe0c110812 to your computer and use it in GitHub Desktop.
dropdown array of states in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * set up dropdown for states | |
| * | |
| * @return states | |
| */ | |
| static function states_select( $name = 'niica_member_state', $user_id = 0 ) { | |
| // fetch the current status | |
| $current = get_user_meta( $user_id, 'niica_member_state', true ); | |
| $current = !empty( $current ) ? esc_attr( $current ) : 'none'; | |
| $states = 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', | |
| 'DC' => 'Washington D.C.' | |
| ); | |
| $drop = ''; | |
| $drop .= '<select id="'.$name.'" name="'.$name.'" class="member-state-drop">'; | |
| $drop .= '<option value="none" '.selected( 'none', $current, false ).'>(Select)</option>'; | |
| foreach ( $states as $value => $label ) : | |
| $drop .= '<option value="'.$value.'" '.selected( $value, $current, false ).'>'.esc_attr( $label ).'</option>'; | |
| endforeach; | |
| $drop .= '</select>'; | |
| return $drop; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment