Created
June 21, 2016 18:05
-
-
Save joshfeck/86a93df2cddfa7efba7427e66ab0b22b to your computer and use it in GitHub Desktop.
Rough and tumble quick and dirty example of how to add some custom JavaScript validation to an EE4 form field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add script to registration form | |
add_action( 'AHEE__attendee_information__reg_step_start', 'eea_custom_validation' ); | |
function eea_custom_validation() { | |
?> | |
<script> | |
jQuery(document).ready(function($) { | |
$('.ee-reg-qstn-78').keyup(function() { // use your unique input class | |
$('span.error-keyup-78').remove(); | |
var inputVal = $(this).val(); | |
var characterReg = /^\s*[a-zA-Z0-9,\s]+\s*$/; // your custom regex, this checks for special characters | |
if(!characterReg.test(inputVal)) { | |
$(this).after('<span class="error ee-required-text error-keyup-78">Only a-z and 0-9 please.</span>'); | |
} | |
}); | |
// handle the submit button | |
$('#spco-go-to-step-finalize_registration-submit').click(function() { | |
if($('span.error').length > 0){ | |
alert('Please correct the errors in the form.'); | |
return false; | |
} | |
}); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment