× Form Help

Age Restrict

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

nicko22 replied the topic: Age Restrict

Hi Mihaela,

This is working great thank you.

Is there a way to expand on this my having an element become visible when the date of birth is out of the range.

For example:
- they are too old or too young
- a message appears (element) saying you are outside of our criteria.

Thanks
Nick
#236240
  • Posts: 2348
  • Karma: 85
  • Thank you received: 315

mihaela replied the topic: Age Restrict

Hello again,

Yes, there is a way to make this work as you want.

The simplest solution for this is to use this code as the validation script for the calendar element.

So, instead of using this script in Initialization script area, go to Properties of the calendar element. In the Validation section check the "Required" checkbox and set the Validation Type to "Custom".

In the code area below put the following code:
function ff_dateField_validation(element, message)
{
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) {
        if (message=='') message = "Entered age should be between 7 and 8.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    else if(age == 7 || age == 8) { return '';}
    else {
        if (message=='') message = "Entered age should be between 7 and 8.\n"
        ff_validationFocus(element.name);
        return message;
    }
} // ff_dateField_validation
NOTE: In the code above you have to replace dateField with the Name of the calendar element in your form.

That should do the trick. This way user shouldn't be able to submit the form unless age is 7 or 8.

Let me know whether you've managed to set this for your form.

Regards,

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

nicko22 replied the topic: Age Restrict

Brill - thanks again for your support :)
#236271
  • Posts: 2348
  • Karma: 85
  • Thank you received: 315

mihaela replied the topic: Age Restrict

I'm glad I've helped and that it works as wanted. :)

Regards,

Mihaela
#236272
Moderators: ForumSupporttomeperica
Time to create page: 0.074 seconds

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!

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