Alright… aside from music, I like to program a bit.  Although for the most part, I have walked away from IT related work.

This is a super short project that I’ve noticed a lot of people have been trying to figure out how to do.

I’ve seen a lot of difficult explanations online, which have frustrated me, because this is not a complex thing to do.

With that said, here is the “Super-simple Solution For Passing Cookies Through Gravity Forms!”

Code For Passing Cookies With Gravity Forms

If you use Gravity Forms and want to pass a cookie through a hidden field (or any field for that matter) this is what you do.

Add the following code to your theme’s functions.php file:

add_filter(“gform_field_value_your_parameter_name“, “populate_affiliate”);
function populate_affiliate($value){
return $_COOKIE[“your_cookie_name“];

The two parts (‘your_parameter_name’ and ‘your_cookie_name’) will need to be set to match your values.  So let’s set those values!

When editing or creating your gravity form, you will want to define the parameter name and checkmark the box as shown in the image below:
gravity-form-cookie-parameterAs you can see, I named the Parameter ‘affiliate_id.’  Therefore my code would be:

add_filter(“gform_field_value_affiliate_id”, “populate_affiliate”);

The only other value you need, is the cookie.  If you’ve gotten this far, you should already know what you named your cookie.  But if you still aren’t sure, just do a google search on ‘how to find cookie name.’  It’s easy to do.

That’s it!  When the form is submitted, you will now receive the hidden value that was stored in the cookie.  Be sure that you have set the form output to include this part of the form.

Have any questions?