validate 2 recaptchas on memsa pagina por ajax

0

Talk galley blz? I need a help I implemented 3 recaptchas on the same page.

<form id='form1'><div class="g-recaptcha" id="Login" data-sitekey="minhakey"></div></form>

<form id='form2'><div class="g-recaptcha" id="reset" data-sitekey="minhakey"></div></form>

<form id='form3'><div class="g-recaptcha" id="email" data-sitekey="minhakey"></div></form>

In my js file I put the following code.

var CaptchaCallback = function(){
    $('.g-recaptcha').each(function(index, el) {
        grecaptcha.render(el, {'sitekey' : 'minhakey'});
    });
};

and finally in the footer

<script src="https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit"asyncdefer>
That'sokay.itgeneratesthepagewiththe3formsandthe3reCAPTCHAStheproblemisinvalidationwhenIusegrecaptcha.getResponse()itonlyworksforthefirstrecaptcha.fortheother2doesnotworkSoIfoundongooglethatifIuzarthiswayitwouldwork

grecaptcha.getResponse(elementId);

ThenIusedvarresponse=grecaptcha.getResponse(reset);

Sowhendoingthisinsteadofrecordingitinthevariableresponseitmakesarequestinmypagewiththeresponseandmypageupdateswiththeurlofmysite+theresponse

  

link

Has anyone ever faced this problem or does anyone know how to solve it? thank you in advance;

I did as you said:

var reLogin;
var reLost;
var reRegister;
var onloadCallback = function() {

    var reLogin = grecaptcha.render($('#reLogin')[0], {'sitekey' : '6LcZ-wsUAAAAAOkcUWs5OiVIQW6Td2aIYPf8aMxe'});
    var reLost = grecaptcha.render($('#reLost')[0], {'sitekey' : '6LcZ-wsUAAAAAOkcUWs5OiVIQW6Td2aIYPf8aMxe'});
    var reRegister = grecaptcha.render($('#reRegister')[0], {'sitekey' : '6LcZ-wsUAAAAAOkcUWs5OiVIQW6Td2aIYPf8aMxe'});
};

and my onclick validation

alert(grecaptcha.getResponse(reLost));

Only the alert comes in.

    
asked by anonymous 16.11.2016 / 00:42

1 answer

1

The grecaptcha.getResponse(elementId) expects a reference that grecaptcha.render(el, {'sitekey' : 'minhakey'}) returned to you, not the DOM id ( id='reset' , id='email' , etc).

I would, for each of the captchas:

var reset = grecaptcha.render($('#reset')[0], {'sitekey' : 'minhakey'})

grecaptcha.getResponse(reset);

Instead of the .each loop you've made.

    
16.11.2016 / 00:49