Skip to content

Gravity Forms merge tags as Default Value for form fields

If you’re new to Gravity Forms merge tags you may think, what the hell is a merge tag? Well they’re placeholders that are replaced dynamically by the value associated to them when used in some places like notifications or confirmations content and the default value setting for fields that supports it.

By default Gravity Forms provides a bunch of useful merge tags to insert values like the first name or the email of the currently logged user, the IP of the user, the title or ID of the page from where the user is submitting the form, or even the value of a custom post meta, and many other interesting data, I would recommend you to take a look to the Gravity Forms merge tags doc page to check them all.

I’m going to show you some real use case examples of how you can use the merge tags based on commonly asked questions that we see in support.

How to use the same form in all your pages but know where the user was when submitted the form

Simply using the {embed_post:post_title} from the embed post merge tags as default value for a hidden field in your form you can know that.

{embed_post:post_title} Gravity Forms merge tag

If you want to use this information for conditional logic rules, for example to show one confirmation or another based on this. I would recommend you to use the {embed_post:ID} instead, because you may want to change your page titles at some point and that would require to update all your conditional logic rules, but your post/page id will not change never.

Pre-populate the user first name and last name when the user is logged in

Using {user:first_name} and {user:last_name} from the user meta merge tags as default values in a name field will do the job.

Gravity Forms user meta merge tags

Obviously if the user is not logged in, or there’s nothing saved in the user profile for first and last name nothing will be pre-populated into your field :)

The user meta merge tags are not limited to the default WP user meta, you can use them for any data stored in the user meta table. So for example, if you’re using WooCommerce and prefer to use the billing first and last name you can replace the above merge tags by {user:billing_first_name} and {user:billing_last_name} you just need to know the meta key that is used to store the information that you want to populate and put it after the {user: part of the merge tag.

Include the IP of the user submitting the form as part of the entry fields

Gravity Forms automatically saves the IP of the user as part of the entry meta data, so you don’t really need to do anything to have it in your entry, you can see it checking the entry detail page and you can also get it from $entry if you’re creating a custom function. But maybe you just want a simple and easy way to save the IP into a field of the entry. Your wishes are my commands :) This time you want to use the {ip} merge tag as default value.

Gravity Forms IP Merge Tag

Get the value from a custom field of your post/page

Now you will need to use the custom field merge tag. This merge tag it’s a bit different from the others, you need to edit it to add the meta key used to save the data in the custom field of your post/page. The format is very easy: {custom_field:[name]}

You will need to replace [name] with the meta key name for your custom field. In this example I’m going to use author_email as meta key name. It’s very easy right? Well many people get confused with this, so let me show you how my custom field looks in the post editor page and how the merge tag must look in the default value setting for the field to work properly:

Post Custom Field
author_email is the meta key name of my custom field in this post
Gravity Forms Custom Field Merge Tag
And this is my merge tag to get it populated into the field.

Add the HTTP referer information to a hidden field

Simply by using the {referer} merge tag as Default Value you can store the HTTP_REFERER information provided by your server headers to a field.

Gravity Forms Referer Merge Tag

Bear in mind the HTTP_REFERER stores only the URL of the previous page, so you can’t use this to track a complex route to the page where your form is embedded, only to know the previous page the user visited before clicking on the link that allowed him to load the page where you have for form embedded.

All the above merge tags can be used directly in the notifications and confirmations content too. So you don’t need to put them into fields if you just want to show the information in a notification or a confirmation content but don’t need to save the information as part of the entry fields.

Hopefully at this point you’re now a master of Gravity Forms merge tags! :D

Published inGravity Forms

23 Comments

  1. Roston Roston

    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.

    • Samuel Aguilera Samuel Aguilera

      I’m sorry Roston but I don’t understand what you’re asking exactly…

    • Chris Chris

      Did you get these working? They work by default. What are you trying to do? Maybe I can sort out the problem.

  2. Bas Smits Bas Smits

    These tags are quite usefull. Is there a simple way to use the Woo-commerce addressfields of the logged in user this way?

    • Bas Smits Bas Smits

      Nevermind: found it: {user:XYZ} does the trick.
      So to populate a gravityform with for woocommerce field Company name you can use:

      {user:billing_company}

      as default value.

      <3 Gravity ;)

  3. Kendra Little Kendra Little

    This was very helpful! Much easier than some other posts on the internet say. Thanks!

  4. Sushi Sushi

    Nice article, thank you!
    I’ve just tried to merge a text-field for using it as an email-address, but failed. I just need to request the visitor to enter a “username” into a text-field of the form, and after “Submit” the visitor should receive a confirmation to an email-address, that consists of the “username” and a pre-defined value such as “@mydomain.com”, so that an email-confirmation will be send to username@mydomain.com
    Is this possible?

    • Samuel Aguilera Samuel Aguilera

      Yes, you can do that in GF but has no relation with the topic of this article.

    • Sushi Sushi

      Thank you for your reply to my comment. Sorry if my request didn’t fit so well. I was trying to “merge” those tags {username} and the pre-defined {@mydomain.com} in a hidden extra field {mail} and tried to use this as the motification, which did not work out. So obviously I was completely wrong with my assumption. So I will try to contact the GF support or hire a dev to help me with this purpose …

  5. Werner Wessels Werner Wessels

    Hi Samuel.

    Maybe im being stupid, but i need the following to happen:
    1. User registers using Gravity Forms Registration form. In this for I created additional fields such as Vehichle registration number.
    2. When users completes a form on the website, ALL fields already completed in the registration process is autofilled, such as Vehicle registration.

    How can this be achieved? For example: Create vehicle_registration in the regsitration form, the use {custom_field:vehicle_registration} as default value. It seems easy, but its not working for me.

    Thanks!

    • Samuel Aguilera Samuel Aguilera

      If you check the examples above, you will see the merge tags to get some value from the user meta are not something like {custom_field:vehicle_registration} but {user:vehicle_registration}

  6. mart mart

    Hi Samuel, I need the display the amount of characters of a hidden field.
    Is there a merge tag too?

    Thanks a lot.

    • Samuel Aguilera Samuel Aguilera

      I’m afraid there’s not any merge tag for that specific purpose, but you can use the gform_replace_merge_tags filter to create your own custom merge tag if you have coding experience.

  7. Victor Victor

    Hey Samuel,

    In my form i have a input type select that shows a list of all my custom_posts.

    Is there a way to combine conditional logic in order to show the custom_field {price} after a selection on the parent field is made?

    Something like:

    If select = BMW x6, input value = {price:BMW x6}
    If select = BMW x3, input value = {price:BMW x3}

    Thank you

  8. Ismael Ismael

    Hi Samuel.

    Thanks for your post!.

    I’m having an issue with this: i’m populating the user firstname, lastname and email as you show in the examples but the fields show the data of another user (the first to open the page that day).

    For example:

    1) User PEPE ARGENTO log into the site and open the form page. The fiels are prepopulated correctly.
    2) User SAMUEL AGUILERA log into the site (froma nother device) and open the same page, but the name and email fields shown PEPE ARGENTO instread the real name.

    This happends until i make an update to the page (save it again in the backend of WP).

    Did you had this issue? I’ve disabled all other plugins but it’s the same

    Thaks!

    • Samuel Aguilera Samuel Aguilera

      Your issue description points to your page being cached by a plugin, a server module, or CDN. Caching pages where you expect dynamic data to happen it’s a well known bad practice, you will want to exclude that page from caching.

  9. Tyler Tyler

    Hi Samuel,

    I recently took on a project that plans to use Gravity Forms to assist with coaching conversations between a Supervisor and a member of their team. Part of the workflow is the Supervisor reviewing the form with the team member before signing and submitting together on the same device.

    My use case is as follows:

    Supervisor selects a name from the “User” field via drop down or AJAX search.
    Later in the form, in either a HTML field or Paragraph Text field within the default value, a merge tag dynamically updates that content from the selection earlier.
    This would all occur before the form was submitted.

    I’ve tried various merge tag combinations but have been unable to get it to work.

    Is this possible with native Gravity Forms?

    I saw some of your other notes reference third party plugins for other use cases. Is that what I need to pursue for this use case?

    Thank you so much for the blog. While I’ve only been trying to fix this issue currently, I’ve enjoyed reading other articles in there!

    • Samuel Aguilera Samuel Aguilera

      Merge tags can’t act as dynamic placeholders, they’re intended to output data that is already known, and the Default Value setting means what you put in it (a merge tag or something else) will be added to the field before displaying the form. So the use case you described can’t be achieved using this tutorial. The Gravity Forms Populate Anything plugin recommended to Victor in a previous comment maybe could fit your needs, feel free to confirm it with the author.

  10. Dakota Dakota

    Hello,

    I’m looking to see if it’s possible to use merge tags to pull data from a nested form into the parent form.

    For example: Somebody checks a box in the nested form, I want it to be able to populate a field in the parent form (so that it can be used for conditional formatting).

    Is this possible?

    • Samuel Aguilera Samuel Aguilera

      I don’t think merge tags can be used that way with nested forms, but I don’t have any experience with the Gravity Perks Nested Forms add-on, so I would recommend you to ask this question to its author.

      That said there’s another perk called Populate Anything, that maybe could be more feasible for your use case.

      In any case, the author of these add-ons is the one who can confirm you which one can fit your needs better.

  11. Vincent Lotin Vincent Lotin

    Hi Samuel,
    I’m looking to see if it’s possible to use merge tags to pull the “ID entry” on a form ?
    In fact, I want to have an automatic numbering of my form and my first idea is to pull the “ID entry” but it doesn’t work.

    An idea ?

    Thanks
    Vincent

    • Samuel Aguilera Samuel Aguilera

      You can use the :id modifier for the {entry} merge tag. So it would be: {entry:id}

      But as the entry ID is only available after submission, you would need to use a small snippet to process the merge tag before saving the field value to the database:

      add_filter( 'gform_save_field_value', 'replace_awkward_merge_tags', 10, 4 );
      function replace_awkward_merge_tags( $value, $entry, $field, $form ) {
      $value = GFCommon::replace_variables( $value, $form, $entry );
      return $value;
      }

Leave a Reply

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