Limit States in Address Field ONLY on Specific Forms/Fields

Gravity Forms has documentation that can limit the address field to specific states:

The code looks like this:

add_filter( 'gform_us_states’, 'filter_us_states' );
function filter_us_states( $states ) {
    $omit_states = array(
        'Alaska',
        'Hawaii'
    );

    foreach ( $states as $key => $state ) {
        if ( in_array( $state, $omit_states ) ) {
            unset( $states[ $key ] );
        }
    }

    return $states;
}

I have two questions:

  1. How can I apply this code to a specific Field within a specific form? In my case, field 77 in form 22.
  2. I actually have multiple form/field combinations that this same filter would need to apply to. Can I have one same function filter it out for say (form 77, field 22) AND (form 4, field 8) AND (form 5, field 8), etc.? Or do I need to just write it as a new function for every form/field combination?

Any help and clarity would be greatly appreciated.

The gform_us_states filter will apply to all address fields in all forms on the site. There is no way to restrict that to specific fields or forms. If you want more control over the states being presented, I recommend using individual fields for the address parts, and configuring the states for each form specifically. Thank you.

Hi Chris,

Is it possible to consider a future enhancement to allow this filter to be applied per field/form? Most anyone who does online business doesn’t want to limit the Billing Address Field for a credit card, but a lot of us have state limitations on where we can ship or where we do business. Therefore on the same form, we would need one field to have the filter (shipping) but not the Billing address.

There are 2 problems that I see using a separate stand-along drop down field for states:

  1. We can no longer use the “Display option to use the values submitted in different field” on our Billing Address, since the State for our Shipping address won’t get pulled in if it is a stand-alone item.
  2. We are trying to use Google Places API to auto-complete addresses. We got it to work with the standard address field. But now, if we move the state field to a stand-alone field, the auto-complete google places API doesn’t fill that field :frowning:
  3. Lastly, because of the State field positioning being before the Zip Code, we would really have to move both the State and the Zip Code into stand alone fields, making the standard address fields less and less usable.

I would greatly appreciate if the Gravity Forms team could consider making an enhancement to this filter. It would greatly benefit the community that do business online but don’t ship to all states.

Thank you,
Mikhail

I recommend submitting your idea here:

https://www.gravityforms.com/gravity-forms-roadmap/

Thank you.

Hi Chris, I submitted the idea about a month ago. Is there a process for evaluating requests from your team? I haven’t had follow-up, so just wondering what happens with requests such as my own.

Hi Mikhail. There is an internal process for reviewing all the submissions and assigning them to new features. The roadmap was introduced this year, and I am not sure we’ve created any features based on customer submissions at this point. But I believe the intention was to contact individuals for additional information, or to get their feedback when a feature is introduced. You may not be contacted, so I recommend watching the blog and our social media for announcements of new features.

Since your submission, and for many months before that, our focus has been on new add-ons, and the Gravity Forms 2.5 release, so I don’t believe your request would have been evaluated yet. Thank you for sharing your thoughts though. I appreciate it.

Sounds good, Chris. Appreciate the information.