Here it is explained how to allow only people of legal age to submit the form.

In this example, it is assumed that "%d/%m/%Y" date format is used.

To make it able only for people of legal age to submit a form follow these steps:

1) Create a "Calendar" element with format "%d/%m/%Y".

2) Go to Properties of that calendar element, scroll down and in the "Validation" section check the "Required" checkbox, set Type to "Custom".

In the code area that appears below paste the following code:

function ff_CalendarElementName_validation(element, message)
{
   // Checking if the entered date is in right format
   var pattern = /[0-3][0-9]\/(0|1)[0-9]\/(19|20)[0-9]{2}/;
   if(pattern.test(element.value))
   {
      var date_array = element.value.split('/');
      var day = date_array[0];

      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[1] - 1;
      var year = date_array[2];

      // This instruction will create a date object
      birthDate = new Date(year,month,day);

      if(year != birthDate.getFullYear())
      {
         return message == '' ? "Date isn't entered in the right format.\n" : message;
      }

      if(month != birthDate.getMonth())
      {
         return message == '' ? "Date isn't entered in the right format.\n" : message;
      }

      if(day != birthDate.getDate())
      {
         return message == '' ? "Date isn't entered in the right format.\n" : message;
      }
   }
   else
   {
      return message == '' ? "Date isn't entered in the right format.\n" : message;
   }
   
   var now = new Date();
     
   var dobYear = birthDate.getFullYear();
   var dobMonth = birthDate.getMonth();
   var dobDay = birthDate.getDate()

   var age = now.getFullYear() - dobYear;
   var ageMonth = now.getMonth() - dobMonth;
   var ageDay = now.getDate() - dobDay;

   if (ageMonth < 0 || (ageMonth == 0 && ageDay < 0)){
       age = parseInt(age) - 1;
   }

   if (age < 18) {
       if (message=='') message = "Only persons of legal age can submit this form.\n"
       ff_validationFocus(element.name);
       return message;
   } // if
   else if (age  >= 18){ 
       return '';
   }
    
} // ff_CalendarElementName_validation

 

NOTE: In the code above you have to replace "CalendarElementName" with the name of that calendar element in your form.

This way, an error message will appear after clicking on the submit button if the age of the person isn't above 18.

Therefore, only users of legal age will be able to submit the form.

 

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here