Use State Abbreviations : Gravity Forms

To Use State Abbreviations : Gravity Forms, you will not just need the excellent Gravity Forms Plugin for WordPress, but you will also need a Commercial License to allow the code below to work.

The code is added to a proper Child Theme Functions.php file. If you are not using a Child Theme, I suggest you set one up first. Edits to Parent Theme’s are lost on Theme Updates. (That means if you need to update your theme, you will have to redo this work, so a Child Theme is always advised.)

Next, why do we want to do this? My reason is to make passing the Field Value to another application easier. That application wants the State Field to be passed as a two letter standard U.S. State abbreviation (two letters, caps). This is the code:

Note: Made an edit below to the first line after:

"states" => array(

insert on next line:

""=>"",

as this will stop the state of AK from being the default and any Conditional Logic in use based on this field will work as desired. Also allows the Enhanced Interface for this Field.

Below is in use (and includes above edit):

add_filter("gform_address_types", "us_address", 10, 2);
function us_address($address_types, $form_id){
$address_types["us"] = array(
"label" => "United States",
"country" => "USAB",
"zip_label" => "Zip Code",
"state_label" => "State",
"states" => array(
"" => "",
"AL" => "Alabama",
"AK" => "Alaska",
"AZ" => "Arizona",
"AR" => "Arkansas",
"CA" => "California",
"CO" => "Colorado",
"CT" => "Connecticut",
"DE" => "Delaware",
"DC" => "District of Columbia",
"FL" => "Florida",
"GA" => "Georgia",
"GU" => "Guam",
"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",
"PR" => "Puerto Rico",
"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"
));
return $address_types;
}

Note, this list above includes all 50 States, then US Territories, and last are the U.S.Military ones. (Of course, you can edit the list prior to adding to your site, to remove some or change the order.)

When this is done, you will now see:

Gravity Forms State Abbreviations in Form Editor Settings

Gravity Forms State Abbreviations in Form Editor Settings

Gravity Forms State Abbreviations in Form

Gravity Forms State Abbreviations in Form

Gravity Forms State Abbreviations in Form Editor

Gravity Forms State Abbreviations in Form Editor

Hope this was helpful. Let me know in the comments section.

2 thoughts on “Use State Abbreviations : Gravity Forms

  1. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog? My blog site is in the very same niche as yours and my visitors would definitely benefit from some of the information you provide here. Please let me know if this ok with you. Thank you!

Comments are closed.