Gravity form set cookies after confirmaiton

// Gravity form set cookies after confirmaiton
add_action( 'gform_confirmation', 'set_cookie_after_confirmation', 10, 4 );
function set_cookie_after_confirmation( $confirmation, $form, $entry, $ajax ) {
    ?>
    <script type="text/javascript">
        // Function to set the cookie
        function setCookie(name, value, days) {
            var expires = "";
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                expires = "; expires=" + date.toUTCString();
            }
            document.cookie = name + "=" + (value || "") + expires + "; path=/";
        }

        // Set your cookie here
        setCookie('parent_corner_show_content', 'true', 30); // Change 'your_cookie_name' and 'your_cookie_value' accordingly
    </script>
    <?php
    return $confirmation;
}

Leave a Reply

Your email address will not be published. Required fields are marked *