WPForms State Dropdown

Add a dropdown field to your form, and under “Advanced Options” add “dynamic-state” as a CSS class.  Then add the following code to your theme’s functions.php file or core functionality plugin.

/** * State Dropdown * */ function ea_state_dropdown( $field, $form_data ) { if( 'select' !== $field['type'] ) return $field; $classes = explode( ' ', $form_data['fields'][ $field['id'] ]['css'] ); if( ! in_array( 'dynamic-state', $classes ) ) return $field; $field['choices'] = array(); $states = wpforms_us_states(); foreach( $states as $value => $label ) $field['choices'][] = array( 'label' => $label, 'value' => $value ); return $field; } add_filter( 'wpforms_field_data', 'ea_state_dropdown', 20, 2 );

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk