Out of the box, Gravity Forms doesn’t include Australian states as a drop down list.
But luckily, Gravity Forms provides a hook that we can easily add in Australian States as a predefined list. The list eliminates user free typing spelling errors and keeps everything consistent.
Add the following code to your functions.php file. Save
Now go back and EDIT your gravity form. Click on the address block which reveals options. Select Australia as the address type. Save.
Preview your form and you will now see the “State” field transformed to a drop down list.
Always use a child theme.
Pro Tip: This can be modified to suit any country, simply by swapping out the country name and the list of states.
Enjoy!
function australian_address( $address_types, $form_id ) { $address_types['australia'] = array( 'label' => 'Australia', //labels the dropdown 'country' => 'Australia', //sets Australia as default country 'zip_label' => 'Post Code', //what it says 'state_label' => 'State', //as above 'states' => array( '', 'Australian Capital Territory', 'New South Wales', 'Northern Territory', 'Queensland', 'South Australia', 'Tasmania', 'Victoria', 'Western Australia' ) ); return $address_types; } add_filter( 'gform_address_types', 'australian_address', 10, 2 );
0 Comments