0

I have a form with Recaptcha enabled. If the user does NOT verify the Recaptcha and hits submit he/she is prompted to verify by an error message. Then they verify but the submit button remains disabled and the form cannot be submitted. How can I remove the disabled attribute once the Recapthca is verified without the form being refreshed.

My code so far:

   $(".elq-form").validate({

  submitHandler: function (form) {
  var captcha = grecaptcha.render('evbox-recaptcha', {'sitekey' : 
  'my_key'});
   var response = grecaptcha.getResponse(captcha);

    //recaptcha failed validation
    if (response.length === 0) {
      grecaptcha.reset(captcha);
      $('#recaptcha-error').show();
      return false;
    }


    //recaptcha passed validation
    else {
      $('#recaptcha-error').hide();
      $('#submit').attr("disabled",false);
      return true;
    }
  }
});


<p class="field-p">
                  <div id="recaptcha-error" style="display: none">
                    <p>[[%site.text.recaptcha? &topic=`default` &namespace=`site`]]</p>
                  </div>
                  <div id="evbox-recaptcha" class="g-recaptcha" data-sitekey="my_key"></div>
                  <input id="submit" name="submit" type="submit" value="[[%site.button.submit? &topic=`default` &namespace=`site`]]" class="submit-button button button__primary" />
                </p>
madameFerry
  • 219
  • 1
  • 6
  • 20

2 Answers2

0

I think you should check the following:

var captcha = grecaptcha.render('evbox-recaptcha', {'sitekey' : 'my_key'});
var response = grecaptcha.getResponse(captcha);

//recaptcha failed validation
if (response.length === 0) {
  grecaptcha.reset(captcha);
  $('#recaptcha-error').show();
  return false;
}

reference: reCAPTCHA V2 | Google developers

AboElnouR
  • 281
  • 3
  • 14
0

have you tried "attr" instead of "prop"?

$('#submit').attr("disabled",false);

Ref: .prop() vs .attr()

Nikos M.
  • 114
  • 1
  • 8