Form Help

TOPIC:

Age Restrict 1 year 3 months ago #235439

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

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

Age Restrict 1 year 3 months ago #235448

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

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

Age Restrict 1 year 3 months ago #235480

  • Topic Author
  • nicko22
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 14
  • Thanks: 0
Hi,

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

Thanks you

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

Age Restrict 1 year 3 months ago #235483

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

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

Age Restrict 1 year 3 months ago #235515

  • Topic Author
  • nicko22
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 14
  • Thanks: 0
Hi,

That's great.

It's in dd/mm/yyyy format

Thanks

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

Age Restrict 1 year 3 months ago #235528

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 414
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
The following user(s) said Thank You: Eddy.vh

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

Moderators: ForumSupport
Time to create page: 0.055 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!