Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Use Merge Tags as Dynamic Population Parameters

Last updated March 1, 2021 | Written by David Smith 87 Comments

  • August 11, 2019: Improved support for List fields. Updated article with currently applicable fields.

Stop! There's a better way.

This snippet is available as a plugin with Gravity Perks, a suite of over 42 premium Gravity Forms plugins!

  • View the Plugin
  • Buy Gravity Perks

Some complex fields (like Checkbox, Multi Select, List and Single Product fields) do not provide a default value setting. But they do support dynamic population.

This snippet enables the ability to use merge tags as dynamic population parameters, allowing you to specify default values for complex fields.

View CodeDownload Code

How do I install this snippet?

Just copy and paste the code into your theme’s functions.php file.

Do I need to customize the snippet to work with my form?

Nope! This one is generic and will work for all forms out of the box. Here is what it will look like once you’ve added a couple merge tags to your dynamic population parameter settings.

Merge Tags as Dynamic Population Parameters

Does the data I am populating need to be in a specific format?

Yes! Each field expects its data in a specific format.

Field Type Format
Checkboxes First Choice,Second Choice
Multi Select First Choice,Second Choice
List (Single Column) Uno,Dos,Tres
List (Multi-column) Uno|Dos|Tres,Un|Deux|Trois
Single Product (Name) My Product Name
Single Product (Price) 10
Single Product (Qty) 3

Summary

Let me know how you use this in the wild! Be sure to check out the Dynamic Products via Post Meta article which makes use of this handy snippet.

Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 41+ essential add-ons for Gravity Forms with support you can count on.

  • View All Perks
  • Buy Gravity Perks

Filed Under: Snippets

Comments

  1. Bryant Callahan says

    August 19, 2016 at 3:30 pm

    I just added this hoping it would let me dynamically populate columns of a list, but it didn’t seem to work. I know list is a complex field, do you know if this snippet works with list?

    Thanks!

    Reply
    • David Smith says

      August 19, 2016 at 5:19 pm

      It will if the data is in the correct format. Here’s a crash course on List field data: https://www.gravityhelp.com/forums/topic/list-field-help#post-39885

  2. Amanda says

    July 25, 2016 at 3:46 pm

    I can just NOT get this snippet to work and its driving me batty. I’m using Gravity Forms autocomplete to get a field name and then trying to pass that to a taxonomy via a single line field. I’m using the snippet, and the field code {School Name:21} (which is correct)…. just not saving the data whether the single line field is hidden or not.

    Reply
    • David Smith says

      August 8, 2016 at 2:43 pm

      No idea why this wouldn’t work with the autocomplete plugin but I’m glad we were able to help you with an alternate solution via support. :)

  3. Gian Luca says

    May 10, 2016 at 6:15 am

    Hello there! This seems to be exactly what I need. I have only one issue. I want to populate dinamically a product list, like in your referenced tutorial. Perfect. But I also need the values to be selectable by a url parameter. Can I have two parameters? A url parameter and a merge tag?

    Reply
    • David Smith says

      May 24, 2016 at 9:20 am

      I don’t think so, Gian. Not without additional custom code.

  4. Amber says

    March 23, 2016 at 8:38 pm

    Is this supposed to be able to work with field based merge tags (similar to how we can use them in notifications)?

    Right now I have {Name (First):64.3}{Name (Last):64.6} and the fields that I have those tags in don’t dynamically populate.

    Cheers!

    Reply
  5. Trina says

    January 14, 2016 at 8:41 pm

    Hi. Great snippet. Unfortunately I can’t get it to work. I pasted it in exactly, added a new field to my new form for a checkbox, turned on dynamic population and only get a single parameter name field. I didn’t change anything else, I just used the default options of First Choice, Second Choice, Third Choice for the field. Am I missing something? The site is currently under development, so if you would like to see what I’m talking about I can send you login info privately.

    Reply
    • David Smith says

      March 25, 2016 at 12:35 pm

      This doesn’t change how many parameter name fields appear. That is controlled by the field type.

  6. Tim says

    September 26, 2015 at 2:47 pm

    Hey Dave… Can you tell me if it’s possible to use this with a dropdown field that would contain a list of all of the WP users? If so, how?

    Reply
    • David Smith says

      September 26, 2015 at 6:53 pm

      Hi Tim, is your goal to populate a list of users or to preselect which user is selected?

    • Tim says

      September 26, 2015 at 7:08 pm

      Thanks for the quick reply… I actually got what I need working but need one additional thing… I have a populated list of users. Was able to use this code to get it. This is allowing me to view all of the users in a drop down that can be selected on the form. It is storing it in the entries as the user_id… which is great and what I need, but I also need a field (preferably hidden) to be automatically populated with the actual user name or display name. Is that something you could help me with?

      Here’s what I have now.

      [code removed]

    • David Smith says

      September 28, 2015 at 8:31 am

      Hi Tim, do you actually need the user ID for anything? If not, I would say just use this field and change this bit of code so the display name is submitted as the value: http://pastie.org/private/tkfq7mlus1lqk52tvbpaiw

    • Tim says

      September 28, 2015 at 9:02 am

      Unfortunately, I think that I do need the ID just for keeping things in order down the road, such as someone changing their name. The user id will remain constant so I wouldn’t have to change it in multiple locations. Am I out of luck? :(

    • Tim says

      September 28, 2015 at 9:15 am

      Also, when I receive the email notification that from a new entry being added… it shows the Display name (not the id) for that field in the email, so I would think it would be pretty easy to pass that on to another field in the form.

    • David Smith says

      September 28, 2015 at 9:43 am

      Something like this ought to do it: http://pastie.org/private/epfxt8fqohasx3jz1p18va

    • Tim says

      September 28, 2015 at 10:00 am

      Thanks! Where should I put this? I tried adding at the end of my functions.php file, but it breaks the site. Should it go inside the other code that I shared earlier? If so, where? I know that is probably a silly question, and if so, I’m sorry!

    • David Smith says

      September 28, 2015 at 10:32 am

      Hey Tim, just remove the opening <?php tag from the snippet and put back in your functions.php. :)

  7. Joe says

    July 14, 2015 at 11:00 am

    How is this now part of the purchased gravity froms plugin? I am not impressed withthis plugin overpriced, nickle and dime ya

    Reply
    • David Smith says

      July 14, 2015 at 11:23 pm

      Hi Joe, we’ll have to agree to disagree on this one. Gravity Forms provides an insane amount of value. :)

  8. Becky says

    June 2, 2015 at 11:15 am

    Can an extension of this method be used with checkbox fields? I’d like to have a checkbox field on one page, and then on the next page of the form populate another checkbox field with only the items that were checked in the previous field.

    Reply
    • David Smith says

      June 4, 2015 at 7:07 pm

      This snippet wouldn’t help much there. You would need to use the gform_pre_render filter to retrieve the selected values from the first page and populate these inputs into the checkbox field on the second page. If you’d like to commission me to write this snippet, get in touch.

  9. Corydon says

    May 30, 2015 at 5:25 pm

    I was stuck on a project for 2 weeks until I found this snippet. You are awesome!!!!

    Corydon

    Reply
    • David Smith says

      May 31, 2015 at 7:56 am

      Awesome! I’m glad we were able to help. :)

  10. Robin says

    May 19, 2015 at 11:25 am

    Hi David,

    This code is really useful – thanks!

    I was wondering whether you think there would be a way to pre-populate range fields when you add a quantity field? I’d like to set the max value based on the post custom field.

    Thanks, Robin

    Reply
    • David Smith says

      May 19, 2015 at 11:13 pm

      Hi Robin, currently Gravity Forms only supports setting the default value via dynamic population. I’d love to write a snippet to support handling other field properties via dynamic population as well. If you’re interested in commissioning this, get in touch.

  11. Weird Mike says

    December 13, 2014 at 2:22 am

    Would it be possible to dynamically populate check boxes depending on a radio-button selection? I have this form for selecting between 5 options, no matter what’s selected on the radio-button all the options are displayed below after choosing a Yes/No option (just Yes actually, selecting No bypasses this part) and I’m doing this to allow the user to choose more options or minus options for the pre-selected 1-5 options.

    Example: Packages – Bronze, Silver, Gold. When choosing any of these another box appears using Conditional Logic asking if the user wants to add or remove options from each package. The bronze package would have 10 options pre-selected but could choose to take some off or add some.

    Can this be done using this snippet?

    Reply
  12. SMD says

    November 30, 2014 at 8:03 pm

    Hi thanks for this. Does this work for drop down/check ox fields? I have two customer user meta fields that I was to add to a drop down form. Not sure how to popular the drop down with those two merge tags.

    Thanks

    Reply
  13. David Osborn says

    September 18, 2014 at 10:24 pm

    Anything similar to set a drop-down’s default value? I tried to use this snippet to set the default state to {user:thestate} but failed. Thanks.

    Reply
    • David Smith says

      September 19, 2014 at 11:15 am

      I would confirm that the value stored in {user:thestate} is the exact value that is available in your state drop down. I tested locally and it worked for me.

    • Dave Osborn says

      September 19, 2014 at 2:05 pm

      Good call, David. I was trying to match CA to California. It works perfectly now. Thanks!

    • David Smith says

      September 19, 2014 at 2:38 pm

      Awesome! Thanks for confirming.

  14. Nick says

    August 8, 2014 at 2:41 pm

    Hello,

    so far i thought dynamic population requires a submission of form 1, so that form 2 can be populated. Does this snippet work “inside” a form, i.e. displaying pre filled adress fields according to a drop-down selection of the user? I am waiting for this feature. By the way GF support says this will be included in version 1.9.

    Best Nick

    Reply
    • David Smith says

      August 8, 2014 at 7:41 pm

      Hey Nick, this snippet only supports populating values when the form is loaded. Subsequent changes made by the user will not be impacted by this snippet.

    • JD says

      April 27, 2015 at 6:42 am

      Hey Nick, version 1.9 is out. Do you know if Gravity Forms in fact included same-page prepoluation? I am trying to do exactly what you described. Thanks! -JD

  15. Ala says

    July 14, 2014 at 7:36 pm

    Helle, thanks for sharing this solution, i want to add a custom field and display the field data in other form with insert {custom_field:date} in html content but nothing displaying.. how to display information passed in other form.. Thanks

    Reply
  16. Christopher says

    May 29, 2014 at 2:28 am

    Hi David!

    I just want to thank you SO much man! Your kindness in posting this snippit has saved myself and I am sure loads of other newbies hours and hours of time!

    You asked to know how we’ve used it so here goes:

    I am working on a project that will have returning clients, who create a WooCommerce Profile. There are Gravity forms inside the products which they are purchasing. The data captured by the forms is then exported for reporting. It’s NB that all the details about the Member is in the form’s data export, so I am putting the fields already captured in the initial registration, into the form – with the help of your snippet, automatically propigating them with the already stored data ie user:first_name; etc so that they don’t have to fill it in each time. I may even play with the idea of hiding some of the fields from their view – the ones which will not ever be updated :)

    So the good news is that that’s working! The not so good news is that I can’t seem to get data from the DB which are custom ie non-default WP or WooCommerce to propigate into the fields in the forms.

    {user:first_name} pulls through perfectly. Using WP-Members to check the values: in the DB it reflects as first_name. Works like a charm. Now I am trying to get their mobile phone (cellphone) to pull through. Again using WP-Members to check the value: in the DB it reflects cell_phone but doesn’t pull through when I use {user:cell_phone} I am presuming that the ‘user’ bit is incorrect, but I have no idea what prefix to use? :(

    Reply
    • Christopher says

      May 29, 2014 at 2:40 am

      HA! I ditched WP-Members and opened the DB directly. What did I see there? I figured out that your snippet’s actually quering the user meta. Also that WooCommerce saves these with different prefixes than WP does. ie the mobile number I was looking for is actually billing_phone It’s working perfectly now, David. Thank you again SO much!

    • David Smith says

      May 30, 2014 at 6:22 pm

      Thanks for sharing your use-case, Christopher! I’m glad to hear you were able to get your issue sorted. :)

  17. Mike says

    May 13, 2013 at 12:49 pm

    Hi, this looks like just what I need but like Ron I’m having trouble implementing it.

    Could you provide an example of a merge tag to use. I’ve got two name fields in my form and would like to populate the second with their input from the first (but allow them to change it if they are buying it as a gift for someone else). So I’ve tried {Name (First):2.3} (the first name field is ID 2) but it doesn’t do anything. What would be the correct syntax to use?

    Thanks.

    Reply
  18. Ron Richardson says

    March 4, 2013 at 8:00 pm

    Help. Can you provide an example of how to use this?

    I’m using advanced address field as an Employee Address and want to give the choice to auto-populate their Dependent’s Address Fields.

    Is that what this snippet is for? I’m just not quite getting how to use Merge Tags…

    Ron

    Reply
  19. mark says

    June 14, 2012 at 11:46 am

    No, not yet.

    I will look at it a bit more

    Mark

    Reply
  20. mark says

    June 13, 2012 at 8:40 pm

    Hi Dave,

    Can you also use this on lists with multiple colums and rows?

    Thanks

    Mark

    Reply
    • David Smith says

      June 14, 2012 at 10:10 am

      Theoretically it should be possible. Did you already try without success?

Newer Comments »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Recent Posts

  • Spotlight: Gravity Forms Media Library 🤝 Advanced Custom Fields
  • How ANM Powers Internal Finances with GP Unique ID
  • New Release: Gravity Forms QR Code Beta 1
  • How Farbie.at uses GP Inventory to manage over one thousand parties a year
  • Spotlight: Building a Loan Calculator with GP Advanced Calculations

Categories

  • How To (73)
  • News (25)
  • Plugins (19)
  • Releases (13)
  • Resource (3)
  • Snippets (50)
  • Spotlights (15)
  • Tutorials (57)
  • Uncategorized (4)
  • Updates (152)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2022 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Terms & Conditions of Use
  • Privacy Policy
  • Cookies Policy

Want to become a
Gravity Forms wizard?

Join 15,000 readers and be the first to know of legendary discounts, new releases, free snippets, and other secret sorcery!

Download Snippet

Use Merge Tags as Dynamic Population Parameters

  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account