Guide: dynamic population in Gravity Forms

Gravity Forms: Populating fields dynamically (the ultimate guide)

Written by Casey Burridge Marketing Coordinator at GravityKit since 2021, Casey is an expert on Gravity Forms, WordPress, and marketing.

Last updated:

Categories Gravity Forms

Dynamic population is one of the standout features of Gravity Forms. It’s something that more people should be using, and in this post, we’re going to show you exactly how it works.

So why should you care about dyamic population? Well, this functionality is useful if you have the same form on different pages and you need a way to differentiate between submissions. It’s also helpful for personalizing and streamlining the form-filling process!

In this post, we’ll look at the following four ways to pre-populate form fields in Gravity Forms:

  1. Using a shortcode
  2. Using URL query string parameters
  3. The Gutenberg block method
  4. Using a hook and custom code

We’ll also cover some common use-cases for dynamic population, and answer some frequently asked questions about this powerful feature.

Ready? Let’s get started! 😁

What is dynamic population in Gravity Forms?

Dynamic population in Gravity Forms refers to a feature that allows you to pre-fill fields in a form, or pre-select values in a multi-select field (like a Drop Down). This applies to regular fields and Admin/hidden fields!

Try out this demo to see how dynamic population works

On our demo site, we have a donation form. By clicking either of the below links, the “Donation amount” field will pre-populate based on the amount you choose. Go ahead and try it out. (Don’t worry, it’s not a real donation!).

💡 Pro tip: While you’re at it, sign-up for your own free demo site, preloaded with all of our powerful Gravity Forms add-ons!

Why pre-populate fields in your form?

Prepopulating field values in a form is useful for a number of reasons: it makes life easier for the user by reducing the effort required on their part. It also allows you to use the same form to collect information for different things, thereby streamlining your workflow.

For example, let’s say you’re using the same sign-up form on multiple landing pages and you need a way to check which page the user came from. You could pre-fill a hidden form field with the name of the page and include this in the user’s submission!

You can check out dynamic population in action in our tutorial on how to build a support ticketing system using Gravity Forms.

How to enable dynamic field population

Although there are several different methods for dynamically populating fields in Gravity forms, the first step is always the same, and that’s to enable dynamic field population on the field itself!

Here are the steps:

  1. Edit the form where you want to use dynamic population

  2. Click on the specific field that you want to pre-fill

  3. Open the “Advanced” tab in the field settings panel

  4. Check the box labeled “Allow fields to be populated dynamically”

  5. Enter a parameter name in the box and save your form

The parameter name is important because this is how you’ll target that field in order to change its value. The parameter name can be anything. Here’s an example:

A checkbox labeled 'Allow field to be populated dynamically' with an input box below labeled 'Parameter Name'

Now that you’ve enabled dynamic population, you can use one of the methods below to pre-populate your form field. Let’s go through each method, one by one.

1. Dynamically populate fields using a shortcode

The Gravity Forms shortcode allows you to display forms anywhere on your website. The shortcode also accepts a number of parameters allowing you to enable ajax, show the title/description, and populate fields dynamically.

In this case, the parameter we’re interested in is the field_values parameter. Here’s an example of what the shortcode looks like when containing this parameter.

[gravityforms id=“21” field_values=“text_field=Greetings, Earthlings!”]

As you can see, the field_values parameter is followed by the parameter name we gave to our field and then the value we want to populate the field with. If you want to populate multiple fields, you can do this by using an ‘&’ to add multiple field values. Here’s how that would look.

[gravityforms id=“21” field_values=“text_field=Greetings, Earthlings!&another_field=I come in peace”]

And here’s what the output would look like:

A form with two fields, illustrating Gravity Forms dynamic population

It’s important to note that the id parameter is always required. You can find your form ID on the “Forms” page in the column to the right.

When to use the shortcode method

The shortcode method is useful if you want to display the same form on different pages but you require a custom value based on which page the form is on. This method is also useful if you prefer to embed forms using a shortcode rather than a block.

2. Dynamic population using URL query string parameters

Another way to populate fields dynamically in Gravity Forms is to use URL parameters. To do this, append the field parameter along with the value as a key/value pair to the end of the URL, like this:

https://example.com/event-registration/?event_name=Charity%20fun%20run

In this example, the field with the event_name parameter will be populated with “Charity fun run”. Note that we’re using ‘%20’ to denote a space as internet browsers don’t accept spaces in URLs. In fact, all special characters (such as exclamation marks) need proper encoding. If you’re not sure how to do this, check out this free online tool.

When to use this method

Let’s say you own a retail business with multiple store locations and each location has a link to a contact form. Instead of creating a separate form for each store, you could use query parameters to pre-populate a field on a single contact form with the store name so you know which store the user wants to contact.

3. Using the Gravity Forms block

The Gravity Forms Gutenberg block also allows you to pre-populate field values. To start you’ll need to add the block to your page or post by opening the WordPress block editor and searching for the Gravity Forms block.

Next, select your form from the dropdown menu. After that, you should see a preview of your form load inside the editor.

To configure dynamic field population, open the block settings on the right, scroll down to “Advanced”, and enter the field parameter name followed by the value you want to populate it with inside the “Field Values” text box. Your form preview should now update inside the editor, showing the value inside the field.

The WordPress Block editor showing the Gravity Forms block settings

When to use this method

If you prefer to display Gravity Forms using the WordPress block instead of the [gravityforms] shortcode, this method offers a simple way to pre-populate field values.

Using a hook (for developers)

If you’re comfortable adding custom PHP code to your WordPress theme, you can use a hook to dynamically populate form fields in Gravity Forms. For more information about this method, check out the Gravity Forms documentation regarding the gform_field_value_$parameter_name filter.

This method is the most powerful and most flexible out of the four, but it also requires some basic knowledge of WordPress code.

Dynamically populating a hidden field in Gravity Forms

You can also populate hidden fields dynamically using the same methods outlined in this article! So why would you want to dynamically populate a hidden field anyway? There are several reasons. Here are some examples of when you might want to do this:

  • You have a contact form on your site for logged-in users. You could prepopulate a hidden field with the user’s email address and use that as the “Reply to” address in the email notification.
  • You want to track where your form fills are coming from, so you dynamically populate a hidden field with information about where the user came from.
  • You have an event registration form on your site where users can register for different events. You could prepoluate a hidden field with the event information based on the landing page the user was on, or the link that they clicked. This would let you know which event they are interested in without the user needing to specify.

Pre-selecting options in a Drop Down or Checkbox field

So far we’ve shown you how to pre-populate text fields in Gravity Forms but what if you need to pre-select options in a Drop Down, Checkbox, or Radio Buttons field? Well, that’s also possible and the method is almost identical.

When you’ve added the field to your form, open the “Advanced” tab, check the box that says “Allow field to be populated dynamically”, and set a parameter name.

Now, open the “General” tab in the Field Settings, click “Edit Choices”, check the box that says “Show values”, and set a value for each option in your field. The value is what you’ll need to use to auto populate the field.

The Gravity Forms form editor showing field settings for a Drop Down field. Each choice has a value: First Choice, Second Choice, and Third Choice.

For example, if you wanted to pre-select the first option, “Option 1”, you would use the field parameter name and pass the value “first choice”, like so:

[gravityforms id="21" field_values="my_dropdown=first choice"]

As you can see, this is almost identical to how we pre-populated text fields, we’re just using the value of the field option.

Bonus: Dynamically populating field choices

So far we’ve covered how to dynamically populate field values in Gravity Forms, but what if you want to dynamically populate choices in a Drop Down, Radio Buttons, or Multi-Select field?

You can do this using a third-party add-on called Populate Anything by Gravity Wiz. Populate Anything allows you to populate field choices with posts, users, taxonomies, terms, Gravity Forms entries, databases, and more.

Gravity Forms dynamic population: Final thoughts

The ability to auto populate field values is a powerful feature of Gravity Forms. There are four different methods for dynamically populating a field in Gravity Forms: 1) by using a shortcode; 2) using URL query parameters; 3) adding custom code to your site and; 4) using the Gravity Forms block.

You can also dynamically populate field choices for Drop Downs, Radio Buttons, and Multi-Select fields using the Populate Anything “perk” by Gravity Wiz.

For more helpful tips and tricks, read our comprehensive guide on how to use Gravity Forms or check out our toolkit of essential Gravity Forms add-ons.

Helpful tips right in your inbox.

Subscribe to our biweekly newsletter for tips, special offers, and more!

Helpful tips right in your inbox.

Subscribe to our biweekly newsletter for tips, special offers, and more!