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.

Dynamically Populating Gravity Forms Using Checkbox Fields

  1. I'm setting up a series of forms, that I'd like to work like this:

    1. User lands on form #1 and selects from a list of states in a checkbox list.
    2. User clicks submit on form #1 and is redirect to form #2, where a product for each state the user has selected is displayed. (Example: On form #1, user selects Alabama and Alaska. Then on form #2, one dynamic product is created for Alabama and another dynamic product is created for Alaska.
    3. User fills in their contact information for PayPal, and using the Gravity Forms PayPal AddOn, is redirected to PayPal to purchase the two state products.

    So far, I have form #1 working and it dynamically passes "state={Select a State or States Below:3}" as a query string to form #2. Form #2 displays field name "state" as "Alabama, Alaska" but as a single product, not two products. When you hit submit from form #2, it redirects to PayPal but only shows a single product, "Alabama,Alaska".

    You can see the form online here:
    http://attorney.us/website-sign-up/

    *Please note, only the State Domain option is currently working. However, you may also get an idea on where I'm headed with the other options.

    How can I make this work?

    Posted 12 years ago on Tuesday May 8, 2012 | Permalink
  2. Quick follow up: I'd be cool with this working as a Multi Select List also, if that helps. As long as I can pass multiple product options.

    Posted 12 years ago on Tuesday May 8, 2012 | Permalink
  3. The first part of my form is all ready to go now. I have several conditionally based multi select boxes. Each allows a user to select one or more option. Those options can be passed to a second form but I'm struggling on how to finish the functionality of this.

    Thanks for any help you can give me on this!

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  4. Hi Troy,

    You might consider making the "State Domain" a product field and then set up the different state domains as an option field. The benefit is that Option fields support the checkbox field type which can populate multiple values passed via the query string.

    The alternative is to dynamically add fields to the form object via the gform_pre_render hook. You would like have to work through some kinks though as this method is possible but not really intended functionality of this hook.

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  5. If I setup the "State Domain" as a product and then set the different states as options, do I need to pass 50 field data options to the second form?

    I've updated the State, City, and Practice Area options on the form and I'm trying to the second form working again, per your recommendation.

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  6. Hm, I see your point. That wouldn't be very concise would it. Let me cook something up for you. It might not be the full shebang but it'll at least be a decent base to work from.

    Posted 12 years ago on Thursday May 10, 2012 | Permalink
  7. Okie dokie. Here is a snippet that will populate an option field with only values that were passed via the query string.

    http://pastie.org/3887481

    For example, passing this:

    http://localhost/?gf_page=preview&id=150&selected_options=Test 1,Test 2,Test 3,Test 4,Test 5

    Will give you this: http://grab.by/dxmk

    And passing this:

    http://localhost/?gf_page=preview&id=150&selected_options=Idaho,Mexico

    Will give you this: http://grab.by/dxmo

    A few notes:

    1. You can paste this snippet in your theme's functions.php file.
    2. Be sure to update the config options for this snippet as specified via the inline comments.
    3. This method only works where all options are the same value. It is feasible to pass the actually price of the option in query string as well and then split up the label/price and define it dynamically; however, it'd be a bit more work.
    Posted 12 years ago on Thursday May 10, 2012 | Permalink