How to Auto-Fill a Gravity Forms Hidden Field from URL

This Q&A walks through setting up a hidden field in Gravity Forms to pick up values from URL parameters. You’ll see how to enable dynamic population and test with query strings. A sample PHP filter snippet is included for full control.

Do you know Gravity Forms well?

Gravity Forms is a widely used WordPress plugin that lets you build forms—from simple contact forms to advanced surveys—using a visual interface without writing code.

Notable features

  • Drag-and-Drop Interface: Build forms visually.
  • Variety of Field Types: Text fields, dropdowns, checkboxes, radio buttons, file uploads, and more.
  • Conditional Logic: Show or hide fields based on user input.
  • Notifications: Configure email alerts for form submissions.
  • Integrations: Connect with Mailchimp, PayPal, Zapier, and other services.
  • Calculations: Perform on-the-fly calculations within forms.
  • Entry Management: Review, edit, and manage entries directly in WordPress.
  • Spam Protection: Built-in measures to avoid unwanted submissions.

If you need a directory-style display, check out the Gravity Forms Directory addon, which provides a shortcode-based approach, search capabilities, user editing of listings, and an approval process.

Anything specific you’d like to dive into with Gravity Forms?

So I wanted to ask if it's possible to fill in automatically a hidden field in Gravity Forms based on parameters in the URL.

Automatically Populating a Hidden Field from URL Parameters

Yes, you can have a hidden field pick up values from URL parameters. Here’s one way to set it up:

1. Allow Dynamic Population

  • Open your form in Gravity Forms and select the hidden field.
  • Under the Advanced tab, check Allow field to be populated dynamically.
  • In the Parameter Name box, enter the exact name of the URL parameter (for example, utm_campaign).

2. Build the Link

Create a URL like:

https://yourwebsite.com/your-page/?utm_campaign=summer-sale

That hidden field will then be filled with summer-sale.

Things to Keep in Mind

  • Case Sensitivity: Parameter names must match exactly.
  • Correct Field Type: Use a hidden field for this approach.
  • Testing: Verify the setup with different URLs.

If you’d like full control over how parameters are handled, add this snippet to your theme’s functions.php:

add_filter('gform_field_value_your_parameter_name', 'populate_hidden_field');
function populate_hidden_field($value) {
  if (isset($_GET['your_parameter_name'])) {
    return sanitize_text_field($_GET['your_parameter_name']);
  }
  return $value;
}

Need human WordPress help?

WP Assistant is a free tool created by Atiba Software, a WordPress design and development company located in Nashville, TN. If you need more personalized WordPress assistance let us know, and we’ll get back to you ASAP!