0

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 Answers1

0

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

grecaptcha.reset();
$("#g-recaptcha-response").val("");
Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36