Help with age gate using cookies

I am hoping someone could help me with some custom code that if the viewer is 19 or older, the viewer can access the website for 30 days. If they are younger than 19, the Age Gate page remains and the viewer cannot access the website (similar to this https://www.qwestcannabis.com/

I created an Age Gate page but that is as far as I can get.

Here is my share link and the live staging

Thank you in advance!

-A


Here is my site Read-Only: LINK
(how to share your site Read-Only link)

@ambergeron - check out this tutorial by @vincent on setting cookies in Webflow:

Basically when the user inputs the form with their birthdate, you need to calculate if they meet your criteria (great than 19 years old) and then set the cookie value, maybe something like this:

<script>
    $(document).ready(function(){
      if (userAge > 19) {  
        var date = new Date();      
        date.setDate(date.getDate() + 30);
        $.cookie('ofAge', true, { expires: date });
       }
    });
</script>
1 Like

Thank you for the info @sam-g. I re-created my age gate in a new project using tutorial by @vincent. Unfortunately, I am still having issues though… On the published site, once I enter a date of birth, nothing happens… I am pretty sure it must be the code i put in the Before tag.

Here is the read only link: https://preview.webflow.com/preview/ulysses-project-1?utm_medium=preview_link&utm_source=designer&utm_content=ulysses-project-1&preview=dd0d87ba5eb5c7730e127412dba28004&mode=preview

Live staging: https://ulysses-project-1.webflow.io/

Take a look at your browser console. It shows that a variable you are trying to use is not defined.

Thank you @webdev for the feedback. I checked my browser console and see that it is the userAge that is not defined. I have no clue how to code/define this. Would you be able to guide me?

@ambergeron - you’re going to need to define this yourself when the form is submitted. You’ll need to get the users birthday and compare it to the current date when the form was submitted to get the age (in years in this case)

Take a look at this solution on Stack Overflow:

I actually came across a tutorial on how to do this for people who have zero coding experience like me. In case it can help anyone else, the link to the tutorial is here: #21 - Create an age gate to confirm the user's age - YouTube