Forked from joshfeck/ee_add_unique_email_validation.php
Last active
May 10, 2022 20:09
-
-
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.
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
<?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