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.

How to populate dropdown options from database, based on another dropdown?

  1. Hi, I was wondering how exactly to go about this..


    I have a business with multiple locations in various states across the country.

    I have a dropdown list which contains a list of all US states.
    When someone selects a state from the list, a 2nd dropdown populates each location in that state as a new option via a database.


    Posted 11 years ago on Friday February 15, 2013 | Permalink
  2. If you can enter all this in the form when you build it, you can use conditional logic to show specific values in your 2nd drop down, based on a selection in the first drop down (your state.) This will be a lot of conditional logic rules though, and will not be very easy to manage. You could do this with multiple forms, and make it look like one multi-page form. You would use the first form (first page) to select the state, then pass that information to form 2, where you can use the gform_pre_render filter to dynamically populate the 2nd drop down based on the state selection from form 1.

    Here is the documentation for gform_pre_render:

    And here is more information about dynamic population:

    There is no simple way within the form builder to accomplish this, without conditional logic and a ton of rules.

    The other way to do it, with one form, would be to use AJAX to dynamically change the 2nd drop down based on the selection in the first drop down. Here is how one user accomplished that:

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  3. Thank you for the response!

    OK I think the first solution (multiple forms disguised as one) should do the trick.. however how do I keep the appearance of a multi-page form (the progress bar)?

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  4. To keep the appearance of the progress bar, you could add an HTML field to the top of each form and style it statically for the page you're on.

    Posted 11 years ago on Friday February 22, 2013 | Permalink