Ir al contenido

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


  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 know what you’re asking exactly…

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *