Form Help

TOPIC:

Age Restrict 1 year 2 months ago #236240

  • Topic Author
  • nicko22
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 14
  • Thanks: 0
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

Please Log in or Create an account to join the conversation.

Age Restrict 1 year 2 months ago #236264

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
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

Please Log in or Create an account to join the conversation.

Age Restrict 1 year 2 months ago #236271

  • Topic Author
  • nicko22
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 14
  • Thanks: 0
Brill - thanks again for your support :)

Please Log in or Create an account to join the conversation.

Age Restrict 1 year 2 months ago #236272

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
I'm glad I've helped and that it works as wanted. :)

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Age Restrict 1 year 1 month ago #236809

  • ideasgirl
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 5
  • Thanks: 0
Hi, I've tried this and changing it to my requirements the form doesn't do anything. This is my code changed to my needs:
function ff_dateField_validation(element, message)
{
var dateBirth = ff_getElementByName('fecha_nacimiento').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 < 18 || age > 85) {
        if (message=='') message = "Debes ser mayor de 18 años.\n"
        ff_validationFocus(element.name);
        return message;
    } // if
    else if(age == 18 || age == 85) { return '';}
    else {
        if (message=='') message = "Debes ser mayor de 18 años.\n"
        ff_validationFocus(element.name);
        return message;
    }
} // ff_dateField_validation

I'm just doing the validation part as you suggested.

I just need that the person filling up the form to be 18 or older.

Please Log in or Create an account to join the conversation.

Age Restrict 1 year 1 month ago #236826

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
Hello,

There are two reasons why this might not be working for you.

First is that you are not using the correct date format for which this code is written.
The calendar element must represent dates in format dd/mm/yyyy.

Second thing is that these validation messages are displayed after the submit button is pressed. So you have to enter a date so that age is not allowed and press the submit button. Then you should see the error message.

Let me know whether this resolves the issue.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.053 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

Summer Sale!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

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!