0
votes

I am using ajax to submit a form using recaptcha verification.Now since i am using ajax the page cannot refresh.So to check whether user has clicked the recaptcha box i am using the following check

var recaptcha = $("#g-recaptcha-response").val();
if (recaptcha === "") 
{

    alert("Please check the recaptcha");

}

and after form submission recaptcha is reloaded using

grecaptcha.reset();

After the form submission the page is not refreshed and user may have to submit more data using same form.Now the problem is that recaptcha is loaded but var recaptcha = $("#g-recaptcha-response").val(); is returning true due to previous recaptcha submission.

How can i reset the recaptcha response variable?

1
No this is a different question i need to reset recaptcha response variable... - user2656129
Look at the first answer, in your script do you specify render=explicit? I have a feeling that might solve your problem. - Patrick Roberts
Can you just do something like that after form submission grecaptcha.reset();$("#g-recaptcha-response").val("") ? - Victor Leontyev
ok that did it thanks - user2656129

1 Answers

0
votes

After your form submission, you need to reset recaptcha and then erase recaptcha response hidden input:

grecaptcha.reset();
$("#g-recaptcha-response").val("");