Im trying to set a cookie up that has the value of the person email address from the gravity form they submit. I have created a global variable called $users_email and when the user submits the form I am capturing the value of the email field on the form and storing that in the variable.
I then have a set cookie function where I want to create the cookie and give it the value of the person name.
This is what I am currently working with but it doesnt seem to be setting the cookie
function divichild_enqueue_scripts() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'divichild_enqueue_scripts' );
add_action( 'gform_after_submission_2', 'after_submission', 10, 2 );
function after_submission( $entry, $form ) {
global $users_email;
$users_email = rgar( $entry, '7' );
return $users_email;
}
add_action( 'init', 'set_cookie' );
function set_cookie($users_email) {
$cookie_name = "my_visitor";
$cookie_value = $users_email;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
}