Why Create Conditional Choices?
Have you ever wanted to automatically change the available choices in a choice-based field (think Checkboxes, Radio Buttons, Drop Down) based on user input?
The logic behind conditional choices might be something like:
If the value of Field A is “Value B” then show (or hide) Choice C in Field D.
A more specific example:
If the Type of Pet field is not “Dog” then “Chew Bone” should not be available in the Pet Accessories field.
Or how about this:
If the Meal Type field is “Lunch” then only show choices that are available for lunch in our Meals field.
This is actually possible in Gravity Forms out of the box but it’ll make your forms a little clunky. How do you do it? You create a copy of your choice-based field for each variation of choices and then use conditional logic to show/hide the appropriate field based on the user’s selections.
This solution works just fine when there are only one or two variations, but anything more than that and your form becomes unwieldy and difficult to maintain.
Is there a more elegant way to solve this problem? Why yes, yes there is. Allow me to introduce you to Populate Anything. It’s the easiest way to populate anything into Gravity Forms.
We’re going to build a form where users can select what kind of pet they have. Depending on which pet type they choose, a Radio Button field is going to display possible accessories for them to purchase.
Before building that user-facing form, we first need to create a mapping form. This form is used to map out the different pet accessories and which pet they belong to.
Once we have entries for all of our pet accessory combinations, we will build the user-facing form using Populate Anything. Let’s get started.
Step 1 – Create a Mapping Form
We are going to make a form to store our source items and conditional values. Then, we will map those values to a Radio Button field in our user-facing form. Note this technique will work with any choice-based field (e.g. Drop Down, Radio Button, Checkbox, Multi-select).
Start by adding a Radio Button field to the mapping form and set the choices to the different Pet types.
Then, add a Text field. In this field, we will we will input each of our pet accessories.
Step 2 – Submit Form Entries
With the fields added to your mapping form, submit entries for every pet/accessory combination.
Once all entries are submitted, we’ll build the user-facing form.
Step 3 – Create a User-facing Form
With all of the different pet accessories mapped to their appropriate pets, it’s time to build the form our users will see. This form contains two sets of Radio Button fields. The first is identical to the Radio Button field in our mapping form.
In the second Radio Button field, we’re going to use Populate Anything to populate all of the available pet accessories and filter those populated values by the selection made in the Radio Button from above.
With the filter in place, the form will automatically switch the available accessories based on the selected pet.
Taking It Further
Advanced Conditional Choices
Do you need conditional choices with multiple variables? Check out our Create Smart Forms and Advanced Conditional Choices with Gravity Forms article which demonstrates how you can filter choices by multiple user specified values (e.g. meal type and party size).
Check or Select Choices Conditionally
You can take it a step further and let the form automatically make selections in the choice-based field. Check out How to Check Checkboxes (and Other Choice-based Fields) Conditionally for a tutorial on setting that up.
Use Gravity Forms as a Database
If you’re looking for other ways to use Gravity Forms as a simple database, check out Using Gravity Forms as a Simple Database.