Trying to set a custom cookie on form submission [RESOLVED]

Gravity Wiz has a free solution that might address this:

However, if you would like to set a cookie when the form is submitted, you can use the gform_pre_submission filter:

The code to set the cookie might look something like this:

add_action( 'gform_pre_submission', 'set_custom_cookie_pre_submission') ;
function set_custom_cookie_pre_submission( $form ) {
    // Check the form ID if you want to target a specific form
    if ( $form['id'] == 1 ) {
        // Set the cookie name, value, and expiration time
        $cookie_name = 'my_custom_cookie';
        $cookie_value = 'some_value';
        $expiration = time() + ( 86400 * 30 ); // 30 days

        // Set the cookie
        setcookie( $cookie_name, $cookie_value, $expiration, '/' );
    }
}

Then, you would need to read the cookie before showing your content, whenever that needs to happen.

1 Like