× Form Help

Age Restrict

  • nicko22
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 10
  • Thank you received: 0

nicko22 created the topic: Age Restrict

Hi we have a form on our website which allows people to sign upto our youth group.

We want the form to only allow submission if the person is aged between 7 and 8. Is this possible? If so please can you advise.

Thanks in Advance
#235439
  • Posts: 2359
  • Karma: 85
  • Thank you received: 316

mihaela replied the topic: Age Restrict

Hello,

Does your form have a calendar element where the person enters his birthdate or age?

If it does, then a code can be written to disable the submit button in case the calculated age or age entered isn't between 7 and 8.

Regards,

Mihaela
#235448
  • nicko22
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 10
  • Thank you received: 0

nicko22 replied the topic: Age Restrict

Hi,

Yes they use a calendar tool. If you could help with the code it would be fab

Thanks you
#235480
  • Posts: 2359
  • Karma: 85
  • Thank you received: 316

mihaela replied the topic: Age Restrict

Ok,

I can help with the code. To do so I need to know in which format are the dates from the calendar element on your form.

Regards,

Mihaela
#235483
  • nicko22
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 10
  • Thank you received: 0

nicko22 replied the topic: Age Restrict

Hi,

That's great.

It's in dd/mm/yyyy format

Thanks
#235515
  • Posts: 2359
  • Karma: 85
  • Thank you received: 316

mihaela replied the topic: Age Restrict

Hello again,

Please go to form's Advanced properties > More options > Scripts and in the Initialization script set Type to Custom.

In the code area below put the following code:
function ff_FORMNAME_init()
{
setInterval(calAge, 500);
} // ff_FORMNAME_init

function calAge(){
var dateBirth = ff_getElementByName('dateField').value;
    var dobParts = dateBirth.split("/");
     var now = new Date();
  var dobParts = dateBirth.split("/");
  var dob = new Date(dobParts[2], (dobParts[1] - 1), dobParts[0]);
  
  var dobYear = dob.getFullYear();
  var dobMonth = dob.getMonth();
  var dobDay = dob.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 < 7 || age > 8) {
        jQuery("#bfSubmitButton").prop("disabled", true); 
    }
   else if(age == 7 || age == 8)  {
        jQuery("#bfSubmitButton").prop("disabled", null); 
    }
   else {
        jQuery("#bfSubmitButton").prop("disabled", true); 
    }

}
NOTE: In the code above you have to replace FORMNAME with the name of your form.
Also, you must replace dateField with the Name of the calendar element in your form.

What this script should do is it should calculate age. If no date is entered in the calendar field or the calculated are is different from 7 or 8, the submit button will be disabled.

Let me know whether you have managed to apply this to your form and whether this works as you wanted.

Regards,

Mihaela
#235528
The following user(s) said Thank You: Eddy.vh
Moderators: ForumSupporttomeperica
Time to create page: 0.073 seconds

Live Support Chat Opened!

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

Summer Sale!

50% discount on all of our extension subscription plans & templates!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

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