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!
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.
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 47+ essential add-ons for Gravity Forms with support you can count on.
thanks for that!
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.
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,
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.
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. 😃
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
Hi Brad, Populate Anything supports looking up an entry by any field value. You can then populate data from that entry into fields on that form. I’m not clear on how this is intended to integrate with Nested Forms. You can submit a pre-sales question here: https://gravitywiz.com/have-a-question-about-gravity-perks/
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
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.
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.
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.
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.
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.
Don’t have a solution for this one, Bryan.
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.
This works when the form renders but not on page loads. GP Copy Cat might be a better solution for what you’re trying to do.
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?
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)
Is it possible to use it in a nested form ? I tried id but without succes.
Maybe we need to indicate the form id ?
Nope, this is not possible.
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?
This is caused by one of two things (most likely).
This is excellent, thanks so much gravitywiz once again for a very helpful code!Danny
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?
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.
I ended up using code found elsewhere to achieve this. I was simply testing this with a text field.
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.
You can actually use that merge tag directly in the Default Value setting for most field types. Which field type are you using?
I ended up using code found elsewhere to achieve this. I was simply testing this with a text field.
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
Checkbox fields (and other choice-based field types) cannot be populated in this way. This solution should work with Checkbox fields: https://www.gravityhelp.com/documentation/article/dynamically-populating-drop-down-fields/
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
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.
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
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.
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
Glad to help. :)
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
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.
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.
Glad to help, Danny. In Gravity Forms defense, this is not standard usage for merge tags (in fact it requires custom code to implement in this way). If you’re looking for standard documentation on how to use merge tags for their intended purpose, you can find that here: https://www.gravityhelp.com/documentation/article/merge-tags/
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.
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. :)