August 31, 2022: Added
gwlfac_list_field_values
filter to allow filtering the List field values that will be used to populate choices. Improves compatibility with Gravity Flow!February 7, 2022: Migrated to Snippet Library.
June 24, 2014: Added support for a "sort" parameter which will sort the choices alphanumerically based on the "text" value.
January 28, 2014: Fixed issue where requiring a populated choice field failed validation unless the first option was selected.
January 2, 2014: Added example for formatting
value_template
for pricing fields.

I always have a hard time coming up with titles for snippets where the use case for something is not immediately obvious. Here’s a great use case that will help you understand the power of this handy snippet.
Let’s say you have a group activity sign-up form. You offer a variety of activities for groups but you need to know which members of the group will be participating in which activities.
This snippet can help you accomplish this by collecting the group members’ names in a List field and then populating those names in a checkbox field (or any other choice-based field) designated for each activity.
How do I get started?
- Make sure you’re running Gravity Forms v1.7.13 or later.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Copy and paste the snippet into your theme’s functions.php file.
- Awesome! Now you just need to configure the snippet for your Gravity form. See the usage instructions below.
Basic Usage
new GW_List_Field_As_Choices( array(
'form_id' => 1,
'list_field_id' => 2,
'choice_field_ids' => 3
) );
Enable Alphanumeric Sorting for Choices
new GW_List_Field_As_Choices( array(
'form_id' => 1,
'list_field_id' => 2,
'choice_field_ids' => 3,
'sort' => true
) );
Populate Multiple Fields
new GW_List_Field_As_Choices( array(
'form_id' => 384,
'list_field_id' => 3,
'choice_field_ids' => array( 6, 7 )
) );
Customize the Choice Label and Value
new GW_List_Field_As_Choices( array(
'form_id' => 384,
'list_field_id' => 2,
'choice_field_ids' => array( 4, 5 ),
'label_template' => '{Name} <span style="color:#999;font-style:italic;">({Age})</span>',
'value_template' => '{Name}'
) );
Auto List Field auto-syncs the number of rows in a List field with a Number or Quantity field value. It can also count the number of List field rows and use that value in Gravity Forms List field calculations.
This allows you to automatically add or subtract new List field rows based on the number value in another field!
Parameters
The form_id
, list_field_id
, and choice_field_ids
parameters are required. The snippet will fail silently; no error message is displayed.
- form_id (integer) (required) The form ID of your form.
- list_field_id (integer) (required) The field ID of the List field whose submitted values will be used to populate the choice fields.
- choice_field_ids (integer|array) (required) The field ID or fields IDs of the choice-based field(s) that will be populated from the user-entered List field values.
- label_template (string) (optional) Template used to determine how the user-entered data from the List field is used to generate the label of each choice in the choice field. Defaults to ‘{0}’. See Label Template below for more information on this.
- value_template (string) (optional) Description. Defaults to value of
label_template
parameter. See Value Template below for more information on this.
Label Template
Let’s say our List field has two columns: “Name” and “Age”. Now we’ll imagine the user has entered the following data into the list field:
David|26
Laura|27
Lee|19
The default generated choices would be:
David
Laura
Lee
Using the label_template
parameter, we can add additional user-entered data to the label. Simply use the name of the List field column to indicate which data you would like to display.
Template
'{Name}, {Age}'
Choice Labels
David, 26
Laura, 27
Lee, 19
You can also add formatting to further style and customize the choice label.
Template'{Name} ({Age})'
Choice LabelsDavid (26)
Laura (27)
Lee (19)
Value Template
The value of the choice field will default to the label unless you provide a value_template
. This parameter works in the same way as the label_template
. Having separate settings for the label and value templates allows you to have a choice label like “David (26)
” with a value like “David
“.
Value Template for Pricing Fields
If you want to populate a choice-based pricing field, you will need to format the value_template
like so:
value|price
Here is an example with actual values:
{Name}|5.25
Summary
What do you think? This is a pretty cool snippet, huh? As always, if you use it and like it, let me know!
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 46+ essential add-ons for Gravity Forms with support you can count on.
this answer is good guide. thank you
Hi David,
The snippet works with checkboxes, but what if I want to pass the label and value of the selected radio button, how to modify the code?
Hi Oxana,
We have a Perk that allows you to copy values between fields: Gravity Forms Copy Cat. If you have an active Gravity Perks License, you can open a ticket with us via our support form, with your account email so that our developers can take a look into it.
Best,
Hi David, How to adapt this code to populate the checkbox options from another checkbox instead of a list. The checked boxes from the first chekbox are the values for the second one. Thank you for your help
Hi Nebil,
If the first checkbox field will be in another form entry, we have a snippet that works with GP Populate Anything to make it possible to use that Checkbox field choices as choices for the second checkbox field.
However, if both Checkbox fields will be on the same form, then I’m guessing this other tutorial of ours with a similar setup should work for you. In that tutorial, replacing the survey field with a checkbox field should populate the second checkbox field with the choices checked in the first checkbox field.
Best, Best,
This is amazing. It even works with drop downs. You sir are a legend!
How? Please give me some tutorial.
Hi Bhaskarjyoti,
The configuration for Drop Down fields is identical to any other choice-based field. Put the List field on any page previous to the one that includes the Drop Down, and update the parameters in the snippet to reflect the form ID, List field ID, and Drop Down field ID.
Hi David, I like this solution,
I want to do the same things but i didn’t understand when i change “list_field” to other field, the code didn’t work me. please give me any suggestion. Thank you.
Hello there, could you please let us know how you configured the snippet? The best way for us to view that is to send a snippi link including your snippet setup. If you need help troubleshooting the snippet, go ahead and check out this help article. Let us know! 😀
Hi all,
Does anybody know how to adjust this perk to make it work with the gravity survey ranks field? I would like to achieve that the elements of the list can be ranked, not only checked, with the rank survey field.
Many thanks in advance! Jasper
This is a little tricky as Survey fields have special values that are generated to uniquely identify each choice. Certainly possible but something you’d likely need to hire a developer to achieve.
Hi David,
Is there a premium version of this snippet, where users can use a UI to set up for each form instead of messing with functions.php?
If there isn’t, is there a plan on developing one?
Please let me know. Thank you!
Hi Quang, there is no premium version currently; however, we do have plans to add support for this in another upcoming perk. No definite ETA but if you’d like, I can add you to the notification list for that perk. ?
Hi David, I love gravity perks. I have been a subscriber for a few years now.
I have a question about this free perk.
I have two identical forms with one exception. One form has read only fields whereas the second form can only be accessed by admin and those same fields are editable.
Do I need to make a duplicate of the code I have included with the new form_id or do I just add the form_id to the existing function.
‘form)_id’ => 27,45,
Hi Andre, thanks for being a Gravity Perks customer!
You’ll want to duplicate just the configuration code for each form. More details here:
https://gravitywiz.com/documentation/apply-class-based-snippet-different-forms/