Created
February 25, 2017 20:28
-
-
Save joshfeck/7eddc3977ed0ff480fc60a2b00d796aa 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_email_validation(){ | |
wp_add_inline_script( | |
'single_page_checkout', | |
'jQuery( document ).ready(function($) { | |
$(".ee-reg-qstn-email").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 email address"); | |
} );' | |
); | |
} | |
add_action( 'wp_enqueue_scripts', 'ee_add_unique_email_validation', 60 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment