ReCaptcha v2 client side events
Another solution is to set data-callback
directly on the g-recaptcha
div, like this
<script type="text/javascript">
var imNotARobot = function() {
console.info("Button was clicked");
};
</script>
<div class="g-recaptcha" data-callback="imNotARobot" data-sitekey="key"></div>
You can configure reCAPTCHA to give a callback on successful validation using the data-callback attribute on the g-recaptcha tag or via the 'callback' parameter if using explicit rendering.
See https://developers.google.com/recaptcha/docs/display#render_param
Example using explicit rendering:
var myCallback = function(val) { console.log(val); };
grecaptcha.render(
document.getElementsById('my-recaptcha-placeholder'),
{
callback: myCallback,
sitekey: mySiteKey
});