Have you filled out a lifetime of forms? Surely there are some things we can do to reduce Repetitive Form Entry Fatigue (no I will won’t call you Shirley).
While I have it used it super extensively, one of my favorite WordPress plugins Worth Paying for is Gravity Forms. Beyond all the features in packs in to the Dashboard interface, a world of possibility lurks below the hood via custom hooks and filters and stuff.
One of my web design clients runs an annual silent auction. In the past, their organization had people email in their bids, meaning my client was performing a raft of copy/paste to put the information in a spreadsheet. I suggested using Gravity Forms to streamline it. Their first pass was one giant form with like 100+ items; I convinced them to instead create one form that could be embedded into 100+ separate posts for each item.
While Gravity Forms provides among the data it stores for each response the URL of the page the form is embedded in, I knew it is more useful to store the actual name of the item, which in this case, is the title of the post.
To put this into motion, I added a field item to the form, and in the advanced tab, I check the Visibility Option to be hidden
since the site visitor never needs to see it. But the important step here is to check the box for Allow field to be populated dynamically. This opens another setting where I can define a Parameter Name

Setting up a hidden field to be tracked by a parameter named “auction item”
By allowing it to be “populated dynamically” it means my script can set its value, and that value will be stored in a variable named auctionitem.
The code needed to do this is pretty easy via the Gravity Forms gform_field_value_$parameter_name
filter.
For the site I am doing, the code is:
add_filter('gform_field_value_auctionitem', 'populate_auctionitem'); function populate_auctionitem($value){ return get_the_title(); }
When the form is built, it will insert the title to the post into this hidden form, and thus the data goes along for the ride with the other stuff people fill on the form.
But I ran into a problem of my own making. When setting up the site I was pretty sure the sophistication of the theme we chose would cover all the needs of the client. So unlike my usual practice now, I did not create a child theme. The code I wrote above needs to go into the theme’s functions.php
file, and I refuse to modify core theme files which would be lost in an update.
I put into play the Code Snippets plugin which gives me the end around I needed; I can add my custom code in the plugin’s interface, and it operates as if it is in the theme’s functions file (once their auction is done, I offered to move their site to a child theme, where it’s cleaner to add custom code).
The other thing I offered as to do with the above mentioned Form Fatigue. If one person decides to bid on multiple items, on each page they need to enter a name, address, phone, email. And while most browsers do okay with Auto filling forms, it seems more elegant to have those fields already filled out if they have been entered at least once.
This is a job for cookies:

NYTimes Chocolate Chip Cookies flickr photo by Jamison_Judd shared under a Creative Commons (BY) license
I had done this before for a project where the gravity forms auto-filled an email address field. To set this up, the email field in your form needs to be enabled with Allow field to be populated dynamically (under the advanced tab). With great originality, the parameter name I choose is email
.
The code I had used before was:
/* ----- create cookie to remember user name and email for gravity form collecting resources ----- */ add_action("gform_pre_submission_2", "cookify_gf_form"); function cookify_gf_form($form_meta) { $saveVars = array("name", "email"); foreach($form_meta["fields"] as $field) { if (in_array($field["inputName"], $saveVars)) { setcookie("gf_".$field["inputName"], $_POST["input_" . $field["id"]], time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true); } } } add_filter("gform_field_value_name", "populate_name"); function populate_name() { if (isset($_COOKIE["gf_name"])) return $_COOKIE["gf_name"]; } add_filter("gform_field_value_email", "populate_email"); function populate_email() { if (isset($_COOKIE["gf_email"])) return $_COOKIE["gf_email"]; }
This “action” for gform_pre_submission_2
is performed before the Gravity form ID 2 is submitted. The script cycles through the form fields, and if the field is either the name
field or the email
field it saves the value to a cookie. the other functions work to populate the fields like the example above, except the value comes from a cookie.
So I set up the forms the same as above:
I modified all the scripts above to match these additional fields… and it did no save the data when the form was submitted.
That’s because the name field, split into 2 for first name and last’ and the address field, split into several more, doe snot work the same as a single field for a name or email.
Fortunately I found in the Gravity Forms help area a better, more generalized function, that also dealt with this kinds of compound fields:
/* ----- create cookies to remember items for auction gravity forms ----- */ add_action("gform_pre_submission", "pre_submission_handler"); function pre_submission_handler($form_meta) { $saveVars = array("fname", "lname", "addr1", "addr2", "city", "state", "zip", "country", "zip", "phone", "email"); foreach($form_meta["fields"] as $field) { if( $field["allowsPrepopulate"] ){ if( is_array($field["inputs"]) ){ foreach($field["inputs"] as $sub){ $val = $_POST["input_" . str_replace(".", "_", $sub["id"])]; setcookie("gf_".$sub["name"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true); } }else{ $val = $_POST["input_" . $field["id"]]; setcookie("gf_".$field["inputName"], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true); } } } } add_filter("gform_pre_render", "add_auto_update_filters"); $contego_callbacks = array(); function add_auto_update_filters($form){ foreach($form["fields"] as &$field){ if( $field["allowsPrepopulate"] ){ if( is_array($field["inputs"]) ){ foreach($field["inputs"] as $sub){ $fieldName = $sub["name"]; add_filter("gform_field_value_" . $fieldName, function($fieldName) use ($fieldName){ return $_COOKIE["gf_" . $fieldName]; }); } }else{ $fieldName = $field["inputName"]; add_filter("gform_field_value_" . $fieldName, function($fieldName) use ($fieldName){ return $_COOKIE["gf_" . $fieldName]; }); } } } return $form; }
This now works perfectly. Once you have filled out and submitted one form in the auction, on return to any auction form page, your info is magically entered for you (if your name, in this case, is Harry Cantrell
that’s one of my test personalities).

Harry is happy because he does not have to keep typing in the same info on every auction bid page.
But here is why some web cookies are good. Because they are associated with the domain, if the client has other web forms, if they enable populated dynamically for a name, email, address,or phone field, as long as they use the same parameter names, these forms too are auto populated.
It’s a pretty small addition to the experience, and most may not notice it, but it’s sensible approach (I think) for form driven sites.
Don’t make a good person keep filling out the same form fields!
Featured Image: My words (not President Obama’s) superimposed on President Obama filling out his 2010 census form – West Wing Week episode 1 – Future Planes of the Future a Wikimedia Commons photo by The White House shared into the public domain as a US Government work. Have I said lately how much I miss a real Presidential President?
Re the title piece, I think you can also just do default value of {embed_post:post_title} and it’ll get you the site title.
I’ve done a bit of setting of fields via javascript from various page/post values lately as well. It feels lighter weight but that could be my imagination.
I like the cookie. I’ve never really done stuff with those before.
Ahh, that’s easier on default value. Thanks
I don’t think subscribe to comments is working.
Hi Alan, unfortunately this code only works with PHP 7.0 and below. Whit PHP 7.1 return that I can’t use lexical variable $fieldName as a parameter name in line 28. Sorry but I’m not a coder so can you provide the solution that works with PHP 7.1 and above? Huge thanks for the article.
Hi Dilmar,
I’m not sure I have a site to test this on, but I’m looking at the GitHub where it looks like you posted the same question. Following the suggestion above https://github.com/jupitercow/gravity-forms-post-updates/issues/16#issuecomment-335118973 I am guessing the fix should be, in both places this appears:
replace it with:
That’s just a guess. Hope I am lucky.
Hi Alan, thanks for the reply. Unfortunately it doesn’t work (or I can get it work).
Tested:
/* —– create cookies to remember items for auction gravity forms —– */
add_action(“gform_pre_submission”, “pre_submission_handler”);
function pre_submission_handler($form_meta) {
$saveVars = array(“fname”, “lname”, “addr1”, “addr2”, “city”, “state”, “zip”, “country”, “zip”, “phone”, “email”);
foreach($form_meta[“fields”] as $field) {
if( $field[“allowsPrepopulate”] ){
if( is_array($field[“inputs”]) ){
foreach($field[“inputs”] as $sub){
$val = $_POST[“input_” . str_replace(“.”, “_”, $sub[“id”])];
setcookie(“gf_”.$sub[“name”], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
}
}else{
$val = $_POST[“input_” . $field[“id”]];
setcookie(“gf_”.$field[“inputName”], $val, time() + 31536000, COOKIEPATH, COOKIE_DOMAIN, false, true);
}
}
}
}
add_filter(“gform_pre_render”, “add_auto_update_filters”);
$contego_callbacks = array();
function add_auto_update_filters($form){
foreach($form[“fields”] as &$field){
if( $field[“allowsPrepopulate”] ){
if( is_array($field[“inputs”]) ){
foreach($field[“inputs”] as $sub){
$fieldName = $sub[“name”];
add_filter(“gform_field_value_” . $fieldName, function($fn) use ($fieldName) {
return $_COOKIE[“gf_” . $fn];
});
}
}else{
$fieldName = $field[“inputName”];
add_filter(“gform_field_value_” . $fieldName, function($fn) use ($fieldName) {
return $_COOKIE[“gf_” . $fn];
});
}
}
}
return $form;
}
There is no error this time with PHP 7.1 but the function doesn’t work. Sorry but I’m a little dumb with PHP. Can you check this script and see what’s wrong?
Thank’s again!
I dont have access to PHP 7. I just followed the suggestion from https://github.com/jupitercow/gravity-forms-post-updates/issues/16#issuecomment-335118973
The fact that you are not getting an error says the suggestion I sent works. The reason you are not getting is due to some other issue, like the loop conditions not being met. I cant really debug code fragments. Sorry
Solved. In both places this appears:
add_filter(“gform_field_value_” . $fieldName, function($fieldName) use ($fieldName) {
return $_COOKIE[“gf_” . $fieldName];
});
replace it with:
add_filter(“gform_field_value_” . $fieldName, function($fn) use ($fieldName) {
return $_COOKIE[“gf_” . $fieldName];
});
Thanks Alan!
Woot! That’s good news, glad it’s working.