laravel-recaptchav3
laravel-recaptchav3 copied to clipboard
Error with Ajax
Every time a request is sent using ajax, and there is an error, just let it do it once, you have to reload the page to be able to use it again, because it returns the catpcha error. It should have a function to refresh the captcha. I made a login where it returns if the person has active, double authentication, so if it returns yes, it should ask for the code on the same page, but it doesn't stop because if it sends the code at once, it should refresh.
@josuelmm you must reset recaptcha when ajax returned success. Below is example code:
grecaptcha.execute(captchaID, { action: form.attr('action') }). then(function(token) { form.find("[name='g-recaptcha-response']").val(token); });
I hole I helped :)
@josuelmm you must reset recaptcha when ajax returned success. Below is example code:
grecaptcha.execute(captchaID, { action: form.attr('action') }). then(function(token) { form.find("[name='g-recaptcha-response']").val(token); });
I hole I helped :)
Hi . Tanx . but what should be captchaID ? i get this error "Uncaught ReferenceError: captchaID is not defined"
Every time a request is sent using ajax, and there is an error, just let it do it once, you have to reload the page to be able to use it again, because it returns the catpcha error. It should have a function to refresh the captcha. I made a login where it returns if the person has active, double authentication, so if it returns yes, it should ask for the code on the same page, but it doesn't stop because if it sends the code at once, it should refresh.
i am facing same issue, pls give me solution if anyone has
@manishsutariya In my case when I'm creating Bootstrap 5 Modal "in the fly" from AJAX loaded content and in this content I have implemented {!!RecaptchaV3::field('YOUR_RULE_NAME')!!}
, reCaptcha hidden input has no value tag, eg. below:
<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response-XXX">
So I figured out after my modal.show();
I have added:
grecaptcha.execute('YOUR_SITE_KEY', {
action: 'YOUR_RULE_NAME'
}).then(function(token) {
var form = document.getElementById('YOUR_FORM_ID');
form.querySelector("[name='g-recaptcha-response']").value = token;
});
and it works! :) I hope it will help someone!
PS. You can take "SITE_KEY" from <script>
tag like eg.
var site_key = document.querySelector('script[src^="https://www.google.com/recaptcha/api.js"]').src.split('=').pop();