Last active
April 10, 2018 22:09
-
-
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.
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
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