Seagyn Davis
Using Variables to Dynamically Populate Fields in Gravity Forms

Using Variables to Dynamically Populate Fields in Gravity Forms

Reading time of post 1 min readDate when post was published17 March 2014
Disclosure: Some of the links in this post are affiliate links, meaning that if you click on one of the links and purchase an item, I may receive a commission. All opinions however are my own and I do not accept payments for positive reviews. This is just a little way for me to monetize the time I spend writing for you.

I was building a form using Gravity Forms (aff. link) on the Rivers website the other day and came across the need to add a variable used in the back-end of the site and place the value in a form. Gravity Forms does allow you to dynamically set the value of a field and you can quickly do that using a query var. However, I didn't have the ability to set a query var in this case, nor did I want to.

After a bit of research I found a very nifty hook in Gravity Forms which is gform_field_value_my_parameter, where the "my_parameter" is replaced with the name you'd call use to dynamically full in the form - in other words if I wanted a parameter called user_location I would make the hookable action gform_field_value_user_location. I could then use "user_location" as the parameter to populate the field dynamically.

An example of this is:

add_filter('gform_field_value_my_parameter', 'my_custom_population_function'); function my_custom_population_function($value){ return 'yay!'; }

If you had a field being dynamically populated by "my_parameter", its resulting value will be "yay!".

This is very useful for passing information set by the user whilst on your website (login info, location, cart status, errors etc.) and linking it to the powerful Gravity Forms system.

The following companies make my life awesome, maybe they'll make yours awesome too?