PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Can Country be automatically set depending on value in States dropdown?

  1. gmw
    Member

    Per this post http://www.gravityhelp.com/forums/topic/display-us-states-and-canadian-provinces#post-67866, rather than use the Advanced Fields Address group, I created individual fields so I could use a custom list for a States / Provinces dropdown that i needed. Works great!

    Now I'm wondering that if the user can only select a valid state/province, why am I asking him to also tell me what country he is from. By deduction I already know that. Plus I'm opening up the door to inconsistent data. The user could enter New York City, New York and then select Canada for the country. I think that my form needs to be a little more intuitive.

    The reason that I don't delete the country field altogether is that it is useful on "List Entries" screen on the WP Back-end where I can quickly get snapshot of what country my entries are from.

    Based on the value selected in the States / Provinces dropdown mentioned above, is there a way that I could set, via a hook, an Admin-only field (like a checkbox) that would indicate what country the user is from? Or even a hidden field?

    Thanks!

    Posted 9 years ago on Wednesday July 25, 2012 | Permalink
  2. You can do this yourself, but it's not built in to Gravity Forms. This type of functionality is sometimes referred to as dependent drop downs or parent/child drop downs. You see this commonly with automobiles. Select Year > Make > Model (depends on the maker) > Style (depends on the Model), etc.

    Here is one explanation of how to do it.
    http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html

    There are certainly other ways as well. But there is nothing built in to Gravity Forms to accomplish this. Other than Conditional Logic, which will not work with how yours is set up now (I don't think.)

    Posted 9 years ago on Wednesday July 25, 2012 | Permalink
  3. gmw
    Member

    Thanks Chris for your prompt response! So what you are telling me is that if I want to build a form OUTSIDE of GF then I could use a method such as the one you linked to. Within GF there is nothing, currently that I can do.

    I was hoping that there might be some hook available (e.g. when the state field was saved) that would allow me to query the state field and then update an admin-only country field.

    Anyway I'm probably just going to put the country dropdown back on the form and just live with it. Thanks again.

    Posted 9 years ago on Thursday July 26, 2012 | Permalink
  4. There is nothing like that built in to Gravity Forms at the moment. Sorry about that.

    Posted 9 years ago on Thursday July 26, 2012 | Permalink
  5. Matt
    Member

    If I do something like suggested here...
    http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html

    Is there a way / what is the best way to pass the values into hidden fields in gravity forms?

    Is it better to pass by value or reference? Obviously by reference if the user changes it but.... if they don't is there an advantage either way.

    Posted 8 years ago on Tuesday March 26, 2013 | Permalink
  6. I think you can use some AJAX to make this work on the front end. Something like this code a user provided: http://www.gravityhelp.com/forums/topic/gform_pre_render-upon-previous-dropdown-condition#post-137821

    Posted 8 years ago on Sunday March 31, 2013 | Permalink