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

11 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}

Leave a Reply

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