Use Merge Tags as Dynamic Population Parameters

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

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 47 premium Gravity Forms plugins!

View 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.

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.

Comments

  1. Akay
    Akay December 12, 2020 at 8:53 am

    I’m interested in the gravity wiz auto populated. I solely need it for one reason. I have two number fields, and need for the second number field max range value to be populated by the value of the first number field.

    Can this be done?

    If so, can it also be done with range sliders?

    Thank you.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff December 14, 2020 at 9:13 am

      Hi Akay,

      If I understand correctly, you want to dynamically set the max range value of the second number field using the value entered in the first number field? If this correct, then unfortunately this isn’t currently possible with GP Populate Anything. In case I have misunderstood your question and this isn’t what you want, please let us know.

      Best,

  2. Dann Hanks
    Dann Hanks July 23, 2020 at 11:32 am

    hi, I’m trying to reference the users name later in a form. eg, page 1 of form has an input field: Name: then, on page 3 I want to reference what they added here. It’s for a confirmation. Example:

    Form page 1 Name: Bob Smith (standard input for user to add their name)

    Form Page 3 I [Bob Smith] agree to the terms.

    Reply
    1. Ryan Donovan
      Ryan Donovan July 28, 2020 at 12:53 pm

      Hey Dann, we noticed that you were a Gravity Perks customer so we have reached out to you through our support channel for more information. Thank you. 😃

  3. brad holmes
    brad holmes April 4, 2019 at 6:49 pm

    hopefully you can help with a solution, have a form that will be filled out by end user (Form A) and a second form that will will be a nested form for admin only only (Form B) that can group upto 4 from a entries in to a group

    Form B entries need to be to be populated by information taken from A dynamically, i have looked at populate anything, the challenge i have with this is populate anything will only populate the fields from a dropdown selector but this will become very difficult to manage due to Form A being over 2000+ different entries.

    the ideal situation for me would be (Form A) generates a unique id and inside (Form B) we enter the unique Id and it populates information from (Form A) is this possible using gravity perks Unique IDs, populate anything and nested forms.

    As you can tell i would much prefer to find this out before spending £259 and spending days trying to find out if this will work to find out it wont.

    Apologies for hijacking a blog post but can not find a contact for pre sale questions

    Reply
  4. Tiago Freitas
    Tiago Freitas January 20, 2019 at 2:30 pm

    Hi David, I was able to make it work without Populate Anything using the list values with appended group, and then choosing the product price conditional with “ends with”, thereby grouping the options that way. Thank you

    Reply
  5. Tiago Freitas
    Tiago Freitas November 27, 2018 at 12:04 pm

    Not working in product options dropbox…I wanted to populate it from another dropbox value. I have a list of countries, and then wanted to boil it down to a group of countries (coutry x has value Group1) and make a product option that automatically selects the correct group.

    Reply
    1. David Smith
      David Smith Staff December 1, 2018 at 9:28 am

      Hi Tiago, would this be happening “live” on the form as the user makes selections? If so, this sounds like it might be a good fit for our early-access GF Populate Anything perk. If you’re a Gravity Perks user, drop us a line via support and we’ll hook you up.

    2. Tiago Freitas
      Tiago Freitas December 1, 2018 at 11:10 am

      Yes live would be good, but it has to support the Gravity Forms Product Add-ons plugin as I’m using that and it doesn’t support AJAX…

      I’m not using Perks yet, just looking around to see if it can help.

    3. David Smith
      David Smith Staff December 1, 2018 at 8:47 pm

      GF Populate Anything hasn’t been tested with WC GF Product Add-ons… I don’t anticipate any issues and we’ll be happy to fix any that you encounter.

  6. Bryan
    Bryan July 10, 2018 at 6:27 pm

    Any way to use a version of this in order to use merge tags in the min/max range settings of the number field? I’m trying to dynamically insert a custom user meta value into the max setting of a number field. Currently GF just deletes the merge tag on save.

    Reply
  7. Aby
    Aby June 9, 2018 at 1:02 am

    HI DAVID –

    Essentially, Ive just been trying to use a simple numerical input (quantity) which I collect early on in my Gravity form in a nice range slider, and just wanting to copy that as the quantity field for over 60 products (EDD products, and all have a quantity field in them) subsequently (in the same form). This is because the product quantity field comes toward the end and is not sexy enough, besides doesnt flow with logic.

    Ive copied this snippet into functions. CHECKED thoroughly :) … then used {:4} in the parameter name after enabling the dynamic population for the product, as well as other test fields in the same format. The 4 is the ID of the sexy range slider. But Im of course here since the value doesnt update.

    I want it to update instantaneously, all pre submission so the total can be arrived at. Went over your copy perk and it seems it only supports 1 to 1 copy, with sixty products already its insane already. Id love to hear what you say! :) THANKS for all.

    Reply
    1. Aby
      Aby June 11, 2018 at 12:36 pm

      Can I copy one to many in that case – automatically?

      I don’t look forward to making 60 new boxes especially given something could go wrong with the logic.

      Is this going to be easy?

    2. David Smith
      David Smith Staff June 12, 2018 at 2:25 am

      Hi Aby, yes, it should be easy. Let’s say your slider is field ID 1 and you have a bunch of other fields (i.e. 2, 3, 4). You would just add the copy cat class to your slider field like so:

      copy-1-to-2 copy-1-to-3 copy-1-to-4 (etc)

      If you’re copying to the quantity input of a Single Product field, you would need to target the input ID:

      copy-1-to-2.3 copy-1-to-3.3 copy-1-to-4.3 (etc)

  8. Itshak KALFON
    Itshak KALFON May 31, 2018 at 12:17 pm

    Is it possible to use it in a nested form ? I tried id but without succes.

    Maybe we need to indicate the form id ?

    Reply
  9. Brandt
    Brandt December 12, 2017 at 7:44 pm

    This has stopped working for me with the latest WordPress 4.9.1, Flatsome 3.4.2 (I just upgraded from a 2.X version), Gravityforms 2.2.5.13, while using Gravityforms Product Options. I pasted the error below.

    It all worked fine until I upgraded the theme today.

    Any thoughts?

    Reply
    1. David Smith
      David Smith Staff December 15, 2017 at 8:36 am

      This is caused by one of two things (most likely).

      1. There is a theme/plugin that is not returning the correct form object.
      2. You have specified an incorrect form ID in a [gravityforms] shortcode (or anyone else a form ID can be specified).
  10. Parul
    Parul September 10, 2017 at 5:19 am

    Can one do this with a custom field? E.g. I have the user registration plugin for gravity forms and I have a “create user” and “update user” form. If I ask the user’s address in the “create user” form, how can I get the “update user” form to prepopulate with this address?

    Reply
    1. David Smith
      David Smith Staff September 10, 2017 at 8:44 am

      If you’re using a GF User Registration Update Feed, you should just map the fields and the add-on will handle pre-populating the information that is saved in the user meta.

  11. Dave
    Dave June 30, 2017 at 12:27 pm

    This isn’t working for me at all (presuming I understood it correctly…)

    I added your script into functions.php, and then {user:first_name} in the parameter field.

    Reply
    1. David Smith
      David Smith Staff June 30, 2017 at 6:01 pm

      You can actually use that merge tag directly in the Default Value setting for most field types. Which field type are you using?

    2. Dave
      Dave July 1, 2017 at 2:16 pm

      I ended up using code found elsewhere to achieve this. I was simply testing this with a text field.

  12. George
    George June 11, 2017 at 1:30 am

    Hi David,

    I used the code to populate fields from one checkbox fields to another checkbox field but it didn’t work.

    For Ex: The checkbox field with ID:1 has 5 choices and after user selected 2 of the choices I want it to populate to another checkbox field with ID:2

    Thanks, George

    Reply
  13. Sathish Iyer
    Sathish Iyer June 2, 2017 at 12:42 pm

    hey david,

    so i created a user reg form with name and address fields. I created a 2nd form which is a duplicate of the reg form for updates. i copied the snippet into functions.php file. when i use the merge tags from the first form into the advanced field, it does not populate the update file. any thoughts. The user first name last name and email address populate fine. the address field does not.

    Thanks Iyer

    Reply
    1. David Smith
      David Smith Staff June 3, 2017 at 9:45 am

      Hi Sathish, if you’re using the User Registration form, I’d recommend just creating an Update feed for this form to handling populating the user meta back into the form.

  14. Mische
    Mische October 26, 2016 at 4:43 pm

    Hey David – thank you so much for creating this. I have an address field that I’m trying to populate into another form. I have the snippet in the functions file and I’ve created a feed from the 1st form that gives the name to each address field.

    I’ve gone to the 2nd (target) address location and added: {custom_field:zip} (for example) in the dynamic population field. Nothin is showing up.

    What am i missing? Thanks in advance!

    Mische

    Reply
    1. David Smith
      David Smith Staff October 30, 2016 at 11:00 pm

      Does the post/page on which the 2nd form is displayed have a custom field with the “zip” key? If so, I would expect this to work.

    2. Mische Eddins
      Mische Eddins October 31, 2016 at 10:33 am

      Wow. I know that’s the issue. THANK YOU! I’ve been trying to fix this for days and days and have had so many exchanges with Gravity Forms just trying to understand merge tags it’s not even funny. If only someone had mentioned something this simple before, I’d be half as crazy as I am at this point. :)

      You, sir, have just rocked my world. Thank you!!!! Mische

  15. Martin
    Martin September 30, 2016 at 7:24 pm

    Dear David,

    thanks for your great snippets. This snippet is the closes one to solve the problem I have tried it, but it did not seam to work for my problem.

    I have a form with two number field where the user can put in the length and width of the product he wants.

    There is also a checkbox element with the options length and width. Is possible to dynamically populated the checkbox values with the input from the above length and width number fields?

    First I tried to just use the merge_tag in the value field of the checkbox, like the following {length:7} but it just gave me the id 7 back and not the value.

    Another question: Is it possible to use conditional logic in a calculation field of a number element? Like: if checkbox 1 is checked then use {length:7} for a calculation. if not then not.

    I hope, my explanation is not confusing.

    Best Regards Martin

    Reply
    1. David Smith
      David Smith Staff October 1, 2016 at 11:11 am

      Hi Martin, here’s a quick example of how you can map a field value to a checkbox input on submission. http://snippi.com/s/t01q368

      I actually have some code that will allow you to create if/else conditions within a Calculation field’s formula. Get in touch and I’ll be happy to share it with you.

  16. Danny
    Danny August 21, 2016 at 5:24 am

    Thank you so much for the snippet~! I couldn’t believe GF forums / documentation didn’t even cover this to educate customers on how to enable merge tags.

    Reply
    1. Danny
      Danny August 21, 2016 at 11:37 am

      Hey David, thank you for responding.

      I did read the mentioned page. It made me assume I had to add the merge tags into my form only and it’ll automatically work. When it didn’t, my first guess was to look within their forums to find out whether someone experienced similar and what could’ve been the required function to get it working.

      When that didn’t work, I looked online and managed to stumble on this article.

      P.S: I’m no programmer. And GF’s documentation did not say I had to write any custom function to get merge tags working.

    2. David Smith
      David Smith Staff August 21, 2016 at 12:07 pm

      Gotcha. Thanks for clarifying. It seems the point of confusion is that merge tags are intended primarily for notifications and confirmations. Including them in the form itself is a bit of a “advanced” feature. I’ve pinged the documentation manager at Gravity Forms with your feedback. He’s going to update the documentation to be a little more clear on where merge tags can be used out of the box. :)

  17. Bryant Callahan
    Bryant Callahan 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
  18. Amanda
    Amanda 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
    1. David Smith
      David Smith Staff 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. :)

  19. Gian Luca
    Gian Luca 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
  20. Amber
    Amber 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
  21. Trina
    Trina 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
    1. David Smith
      David Smith Staff March 25, 2016 at 12:35 pm

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

  22. Tim
    Tim 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
    1. Tim
      Tim 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]

    2. Tim
      Tim 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? :(

    3. Tim
      Tim 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.

    4. Tim
      Tim 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!

  23. Joe
    Joe 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
    1. David Smith
      David Smith Staff 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. :)

  24. Becky
    Becky 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
    1. David Smith
      David Smith Staff 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.

  25. Robin
    Robin 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
    1. David Smith
      David Smith Staff 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.

  26. Weird Mike
    Weird Mike 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
  27. SMD
    SMD 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
  28. David Osborn
    David Osborn 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
    1. David Smith
      David Smith Staff 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.

  29. Nick
    Nick 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
    1. David Smith
      David Smith Staff 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.

    2. JD
      JD 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

  30. Ala
    Ala 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
  31. Christopher
    Christopher 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
    1. Christopher
      Christopher 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!

    2. David Smith
      David Smith Staff 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. :)

  32. Mike
    Mike 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
  33. Ron Richardson
    Ron Richardson 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

Leave a Reply

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

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

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

Download Snippet

Use Merge Tags as Dynamic Population Parameters

This field is for validation purposes and should be left unchanged.