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 the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

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

Let's Talk