Jump to content

Registrations - Restricting to over 18s


Recommended Posts

Hi,

Apologies if this is a stupid question. Due to the nature of our business, we can not have anyone under the age of 18 purchasing products. Is there a way in PrestaShop 1.3.1 to deny registration to people who put in a date that states they are under the age of 18?

Thank you.

Link to comment
Share on other sites

I suggest that you use Javascript to compare the birthday to the current date. Add something like this in authentication.tpl:

<script language="javascript">
   function checkAge()
   {
       /* the minumum age you want to allow in */
       var min_age = 18;

       /* change "age_form" to whatever your form has for a name="..." */
       var year = parseInt($('#years').value);
       var month = parseInt($('#months').value);
       var day = parseInt($('#days').value);

       var theirDate = new Date((year + min_age), month, day);
       var today = new Date;

       if ((today.getTime() - theirDate.getTime()) < 0) 
       {
           alert("You are too young to enter this site!");
           return false;
       }
       else 
           return true;
   }
</script>



then change line 224 of authentication.tpl:

<input type="submit" name="submitAccount" id="submitAccount" value="{l s='Register'}" class="exclusive" />



Add onclick="return checkAge()" to the button (with straight quotes, not angle quotes). It's annoying how the forums automatically delete onclick events from all posted code.

Link to comment
Share on other sites

  • 7 months later...

I managed to get this working by changing

 var year = parseInt($('#years').value);
var month = parseInt($('#months').value);
var day = parseInt($('#days').value);


to

var year = parseInt(document.forms["account-creation_form"]["years"].value);
        var month = parseInt(document.forms["account-creation_form"]["months"].value);
        var day = parseInt(document.forms["account-creation_form"]["days"].value);



and adding name="account-creation_form" to the necessary form

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...