I currently have a problem with Google's Invisible Captcha. It refuses to load properly despite all my attempts.
The situation: I have a form which is added to the DOM via jQuery when clicking on a button. The form is then displayed in an overlayer which covers the entire screen. At first, no worries but once the form is displayed, I try to render the captcha without success, which prevents doing the execute and thus using the captcha on the form.
Here is the insertion code of my form (which works):
$('.js-event-subscribe').click(function(e){
e.preventDefault();
var event = $(this).data('event');
clearTimeout(ajxTimeout);
if(typeof ajx != "undefined")
ajx.abort();
ajxTimeout = setTimeout(function(){
ajx = $.ajax({
type: 'POST',
url: langPath + '/ajax/event-subscribe/',
data: 'id='+event,
success: function(content){
if($('body').find('#js-event-subscribe').length)
$('body').find('#js-event-subscribe').remove();
$(content).insertAfter('footer');
$('html, body').addClass('opened');
//var test = grecaptcha.render('js-recaptcha-event');
//console.log(test);
//grecaptcha.execute('js-recaptcha-event');
}
});
}, 500);
});
So far it works, the form is correctly added and functional. The grecaptcha.render (according to the documentation) should return the widgetID but reply 0. The "js-recaptcha-event" parameter corresponds to the ID of the DIV captcha in the form (added to the DOM therefore).
<div id="js-recaptcha-event" class="g-recaptcha" data-sitekey="xxxxxxxxx" data-size="invisible"></div>
Therefore the grecaptcha.execute ('js-recaptcha-event') returns an error
Uncaught Error: Invalid site key or not loaded in api.js: js-recaptcha-event
I tried adding the sitekey in render parameters with the same result. :(
The recaptcha API is loaded via (also tested with async & defer in attributes)
<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
Can you tell me what I need to make it work?
Thank you in advance