Support

Home Forums Event Espresso Premium Date of birth validation not stopping form progressing

Date of birth validation not stopping form progressing

Posted: February 14, 2018 at 10:42 am

Viewing 1 reply thread


jacl

February 14, 2018 at 10:42 am

Hi

Really trying to finish this site for launch tomorrow and need to block bad date formats on the registration DOB field.

My code so far is working in that it changes the field green and shows the validation span after the field but on submit it is not stopping them from progressing to make payment

any ideas where im going wrong please

thank you

This is in my functions.php and I;m using moment.js to validate the value to USA format MM/DD/YYYY which works ok


// add script to registration form
add_action( 'AHEE__attendee_information__reg_step_start', 'eea_dob_validation' );

function eea_dob_validation() {
?>
<script>
jQuery(document).ready(function($) {

$('input.ee-reg-qstn-12').change(function() {
$('span.error-keyup-12').remove();

var studentdob = $(this).val();

var studentdobvalidate = moment(studentdob, 'MM/DD/YYYY', true);
//test is USA date... true at end means strict match

if(studentdobvalidate.isValid()) {
$('span.error-keyup-12').remove();
$(this).removeClass( "ee-needs-valid-date" );
$(this).addClass( "ee-has-value" );
} else {

$(this).addClass( "ee-needs-valid-date" );
$(this).removeClass( "ee-has-value" );
$(this).after('<span class="error ee-required-text error-keyup-12">Incorrect format! MM/DD/YYYY only.</span>');
}

});//end keyup function

// handle the submit button
$('#spco-go-to-step-finalize_registration-submit').click(function() {

var studentdob = $('input.ee-reg-qstn-12').val();
var studentdobvalidate = moment(studentdob, 'MM/DD/YYYY', true);//test is USA date... true at end means strict match

if(studentdobvalidate.isValid()) {
//all ok on DOB
} else {

alert('Please use the date picker for date of birth ensuring a US format is used (MM/DD/YYYY).');
return false;
}

});
});
</script>
<?php
}


jacl

February 14, 2018 at 10:50 am

Ha ha why is it you can spent 2-3 hours trying to get something working and the minute you succumb and post in to the forum you then get some kind of inspiration and see the answer 🙂

My click action was on #spco-go-to-step-finalize_registration-submit

when my form is actually using

$(‘#spco-go-to-step-payment_options-submit

So Ive changed to button ID and its now stopping the form from progressing as I wanted…

thanks all sorted

Viewing 1 reply thread

The support post ‘Date of birth validation not stopping form progressing’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso