Getting a cookie value passed into hidden field [RESOLVED]

I’m trying to pass an affiliate click id from a 1st party cookie into a form field. The cookie is working and pulling the query string from the URL and storing it as a cookie.

But no matter what I try, I cannot get it to populate on form fill.

I’ve already tried the below from the help section (gform_field_value_$parameter_name - Gravity Forms Documentation), but with no luck, but I also have no idea if I’ve set it up correctly

add_filter( 'gform_field_value_utm_campaign', 'populate_utm_campaign' );
function populate_utm_campaign( $value ) {
   return $_COOKIE['utm_campaign'];
}

Can anyone offer any advice?

If you have a single line text with, with the box “allow field to be populated dynamically” and then a parameter name of utm_campaign, this code will work just the way it is in the example.

Can you share any screenshots of the way the field is set up, and a link to the form where we can test it?

Thanks for coming back to me Chris. I don’t have a link as I’m currently testing in GTM Tag Assistant.

This is what I actually have:

add_filter( ‘gform_field_irclickid’, ‘populate_irclickid’);
function populate_utm_campaign( $value) {
return$_COOKIE[‘irclickid’];
}

Here’s a screenshot of the form:

You are calling the function name populate_irclickid but you did not change the function name. The function populate_irclickid does not exist: populate_utm_campaign does.

You also used a filter name that does not exist. This is the filter name:
gform_field_value_$PARAMETER_NAME:

If you update the code to this, it will work:

add_filter( 'gform_field_value_irclickid', 'populate_irclickid' );
function populate_irclickid( $value) {
	return $_COOKIE['irclickid'];
}

You can name your function anything you like, like this:

add_filter( 'gform_field_value_irclickid', 'set_tracking_id_field' );
function set_tracking_id_field( $value) {
	return $_COOKIE['irclickid'];
}

If the cookie irclickid exists, this filter gform_field_value_irclickid will populate it with the value from the cookie.

This is super helpful, thank you Chris. I’ve done that and it’s now populating the embedURL but not the irclickid… any thoughts here?

Sorted! Couldn’t have done it without your help! Thank you so much