Jump to content

Age restriction required for firework site


Recommended Posts

My client sells fireworks and needs to make sure that the people buying from the site are over 18. I need to make the Date of Birth required on sign up and to check that the person is over 18, and if not, then to show this error message:
We're sorry, but you need to be over 18 years of age in order to buy from our website.

How can I go about doing this?

I have the latest version of Prestashop

Link to comment
Share on other sites

  • 4 months later...
  • 10 months later...

All I could do was to check the birthday entered when registering to make sure they were over 18. If not, they get this message: You are too young to purchase from this site! Over 18s only.

 

This was added below the other scripts at teh top of authentication.tpl in my theme

 

<script type="text/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(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);

 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 purchase from this site!  Over 18s only");
        return false;
        }
 else
        return true;
           }
</script>

 

Then right at the bottom, an onclick was added to the submit button:

 

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

 

Hope that helps

Link to comment
Share on other sites

  • 1 year later...

All I could do was to check the birthday entered when registering to make sure they were over 18. If not, they get this message: You are too young to purchase from this site! Over 18s only.

 

This was added below the other scripts at teh top of authentication.tpl in my theme

 

<script type="text/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(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);
 
  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 purchase from this site!  Over 18s only");
         return false;
         }
  else
         return true;
            }
</script>
Then right at the bottom, an onclick was added to the submit button:

 

<input type="submit" name="submitAccount" id="submitAccount" value="{l s='Register'}" class="exclusive" onclick="return checkAge()" />
Hope that helps

 

The code

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

should be change to

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

 

This is because the integer value representing the month, begin with 0 for January and not 1.

Link to comment
Share on other sites

  • 1 year later...

 

 

I will not be developing this module any further. Module codebase and rights has been transferred to another member of these forums, to a PrestaShop Gold Certified agency, who I have no doubt will continue to maintain the quality the users of the module have come to expect. All further queries about the module should be made to Marty. 
Link to comment
Share on other sites

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...