Answer the question
In order to leave comments, you need to log in
Why is only the answer from the first captcha processed?
Good afternoon, dear Khabrovites!
I put one captcha on the site and everything worked well. Then I had to put the second and the problems started.
The bottom line is that the processing of the captcha response from the Google server occurs for the captcha that comes first in the DOM. In general, both forms with captcha separately work as they should, but together they don’t.
for the second captcha I can't get grecaptcha.getResponse();
In the headers of the php file, the g-recaptcha-response response is encoded.
Renaming grecaptcha objects to bind them to a specific dom node - didn't help.
Grecaptcha is an object, and it can be referenced somehow, I guess.
I thought that since there are two captchas on the page, there should be two grecaptcha objects, which means they must somehow be put into an array or into a collection and sorted out - it did not work out.
Addressed grecaptcha[0], grecaptcha[1] - hell there.
Is it possible to somehow refer to the second grecaptcha object, or does one overwrite the other?
Answer the question
In order to leave comments, you need to log in
He fiddled, fiddled, and the answer, as expected, was simple:
var recaptchaRequest;
var recaptchaRecall;
var onloadCallback = function() {
// отрисовка recaptcha-request на элементе с id="recaptcha-request"
recaptchaRequest = grecaptcha.render('recaptcha-request', {
'sitekey' : 'публичный-ключ'
});
// отрисовка recaptcha2 на элементе с id="recaptcha2"
recaptchaRecall = grecaptcha.render('recaptcha-recall', {
'sitekey' : 'публичный-ключ'
});
};
var response = grecaptcha.getResponse(recaptchaRecall);
var response = grecaptcha.getResponse(recaptchaRequest);
grecaptcha.ready(function() {
grecaptcha.execute('код', {action: 'url'}).then(function(token) {
// Add your logic to submit to your backend server here.
});
grecaptcha.execute('код2', {action: 'url2'}).then(function(token) {
// Add your logic to submit to your backend server here.
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question