One of the most common uses for Populate Anything is creating Gravity Forms chained selects. For those unfamiliar, a chained select is when a series of choice-based fields are linked together so that the choices made in one field affect the available choices in the next field. Another term that describes this mechanic is filtering. Each drop down filters the next drop down so that only relevant results are displayed.
A familiar version of this is a car selector: you select a year, then a make, and finally a model. Each of the subsequent drop downs changes depending on the selection made in the previous drop down. The reason car selectors use multiple drop downs is two-fold: simplifying the selection process and maximizing performance.
Last time I checked, there have been well over 6000 different car models ever manufactured. If you simply displayed a drop down that contains all 6000 models, it would be overwhelming to select. Can you imagine having to scroll through that list to find your specific car?
Using multiple selectable fields solves both these problems. It simplifies the selection process and maximizes performance. In this article, we’re going to show you how to use Populate Anything to populate large amounts of filtered data into your form.
Getting Started: Creating Your Own Gravity Forms Chained Selects
This article assumes you already have data to populate stored somewhere in the WordPress database. Populate Anything can populate from multiple sources in WordPress, such as Posts, Users, Gravity Forms Entries, and even directly from the database.
In my case, I have a database of cars stored as Custom Posts with custom fields for year, make, and model.
No matter the source, the method is essentially the same: Populate choices into a Drop Down field using Populate Anything, populate additional fields and filter their results based on the previous field’s selection.
- Add First Drop Down and Populate Choices
- Add Second Drop Down, Populate Choices, and Filter the Results
- Add Additional Drop Downs and Filter as Needed
Step 1 – Add First Drop Down and Populate Choices
Start by adding a Drop Down field to your form and give it an appropriate Field Label.
Populate the choices for that field from your source. Since I’m populating from a custom post, I have chosen “Post” as my type and filtered the results to only include the “Car” post type.
In the Choice Template, select the first set of criteria to populate. For our car finder, this is the
year custom field.
Step 2 – Add Second Drop Down, Populate Choices, and Filter the Results
In the second Drop Down, we’re going to populate car makes.
We’ll populate choices like in the first Drop Down, however this time we’re going to filter the results based on the selection made in the first field. This time, we have two filters being applied to the population: post type is “Car” and year is “Year”. The second filter is matching the value of the “Year” Drop Down that we created in Step 1 to the
year custom field in the post. When a user selects a year from the first Drop Down, the Make field will return values that match the given year.
For the Choice Template, we’re populating the
make custom field.
Step 3 – Add Additional Drop Downs and Filter as Needed
This step is basically identical to Step 2. Add another Drop Down and filter the results based on the previous Drop Downs.
With the filters in place, we’ll select the car’s model in the Choice Template.
With the the fields in place with the appropriate population and filter settings, our form displays 3 fields: Year, Make, and Model. The Make and Model fields filter their results based on the previous field, simplifying the selection process for the user and improving performance on the form.
Doesn’t Gravity Forms have a solution for chained selects?
Yes, Gravity Forms offers the Chained Selects Add-On with the Elite license level. In order to use it, you will need to either create a CSV file that will hold all of your available options or write some custom code using available hooks. This approach has a couple of drawbacks that we believe Populate Anything overcomes.
First, the flexibility of Populate Anything shines. Chained Selects is limited to Drop Down fields, where Populate Anything supports Radio Buttons, Checkboxes, and even Multi-Selects. Furthermore, you can populate data based on the final selection in the chain into other fields on your form.
Second, Chained Selects is a single field, whereas Populate Anything uses separate fields. The advantage of separate fields is that you have greater control over the layout of your chained fields.
Third, since Gravity Forms Chained Selects can only be populated from CSV or hooks, your data sources are limited. If you need to update the data for a CSV, you have to manually update the file. Populate Anything can be populated from nearly any data source and updates in real time. This gives you maximum flexibility and any changes to your data source reflect on the form automatically.