Answer the question
In order to leave comments, you need to log in
How to initialize reCAPTCHA V3 via js?
The fact is that if you do the initialization in the standard way, then after successfully submitting the form via AJAX, the error Uncaught Error: No reCAPTCHA clients exist appears in the browser console. and it is not possible to resubmit the form until the page is reloaded.
I just need to re-render the captcha, but this requires its id.
grecaptcha.render(
container,
parameters
)
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
<div id="rcv3_ajaxform"></div>
<script>
var onloadCallback = function() {
var = widget_ajaxform = grecaptcha.render('rcv3_ajaxform', {
'sitekey' : '00000000000-publick-key-000000000000'
});
grecaptcha.execute('widget_ajaxform', { action: 'ajaxform' })
.then(function(token) {
document.getElementById('g-recaptcha-response').value=token;
});
};
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question