Created
August 18, 2018 11:43
-
-
Save miceno/7848fab305fe1a69a06e2965870cb521 to your computer and use it in GitHub Desktop.
Email confirmation for Wordpress Contact Form 7 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
// | |
// Put this file inside your theme in folder js (js/email-confirm.js) | |
// | |
// First we add a hook to the form submit event | |
jQuery( document ).ready( function () { | |
jQuery('.wpcf7-submit').click(function () { | |
// We remove the error to avoid duplicate errors | |
jQuery('.error').remove(); | |
// We create a variable to store our error message | |
var errorMsg = jQuery('<span class="error">Your emails do not match.</span>'); | |
// Then we check our values to see if they match | |
// If they do not match we display the error and we do not allow form to submit | |
if (jQuery('.email').find('input').val() !== jQuery('.email-confirm').find('input').val()) { | |
errorMsg.insertAfter(jQuery('.email-confirm').find('input')); | |
return false; | |
} else { | |
// If they do match we remove the error and we submit the form | |
jQuery('.error').remove(); | |
return true; | |
} | |
}); | |
}); |
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 | |
// | |
// Hook for double check of email addresses. | |
// Taken from: http://stackoverflow.com/questions/6255367/contact-form-7-is-there-a-confirm-e-mail-input-type | |
// Make sure your contact forms include an `email` and `email-confirm` field. | |
// | |
function register_scripts() { | |
if ( !is_admin() ) { | |
// include your script | |
wp_enqueue_script( 'email-confirm', get_stylesheet_directory_uri() . '/js/email-confirm.js' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'register_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment