Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Pebblo/be8ff8e94c7f4d21127f0b9712ad7c39 to your computer and use it in GitHub Desktop.
Save Pebblo/be8ff8e94c7f4d21127f0b9712ad7c39 to your computer and use it in GitHub Desktop.
Add custom email field input validation to check for unique email addresses for each field. You can add this to a site specific plugin.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function ee_add_unique_attendee_validation(){
wp_add_inline_script(
'single_page_checkout',
'jQuery( document ).ready(function($) {
$(".ee-reg-qstn-email").addClass("unique");
$(".ee-reg-qstn-fname").addClass("unique");
$(".ee-reg-qstn-lname").addClass("unique");
$.validator.addMethod("unique", function(value, element) {
var parentForm = $(element).closest("form");
var timeRepeated = 0;
if (value != "") {
$(parentForm.find(":text")).each(function () {
if ($(this).val() === value) {
timeRepeated++;
}
});
}
return timeRepeated === 1 || timeRepeated === 0;
}, "* Duplicate! Please use a unique value");
});'
);
}
add_action( 'wp_enqueue_scripts', 'ee_add_unique_attendee_validation', 60 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment