Skip to content

Instantly share code, notes, and snippets.

@rinogo
Last active April 10, 2018 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinogo/c4177b5d10de62f8703069d7f9a9d68d to your computer and use it in GitHub Desktop.
Save rinogo/c4177b5d10de62f8703069d7f9a9d68d to your computer and use it in GitHub Desktop.
Improved script.js for Contact Form 7 reCAPTCHA Wordpress plugin. It shows an error message if the user fails to check the reCAPTCHA ("I am not a robot") box.
function contact_form_7_recaptcha_callback() {
jQuery(function($){
$('.g-recaptcha-explicit-id').each(function(){
$(this).data('grecaptcha_id', grecaptcha.render($('#' + this.value)[0], {
'sitekey' : contact_form_7_recaptcha_data.sitekey
}));
});
});
};
jQuery(function($){
$('.wpcf7').on('invalid.wpcf7 mailsent.wpcf7', function() {
grecaptcha.reset($('.g-recaptcha-explicit-id', this).data('grecaptcha_id'));
});
$('.wpcf7').on('submit', function() {
var response = grecaptcha.getResponse($('.g-recaptcha-explicit-id', this).data('grecaptcha_id'));
if(!response) {
$('#' + $('.g-recaptcha-explicit-id', this).val()).after('<span class="wpcf7-not-valid-tip">Please check the box.</span>');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment