ReCaptcha: How to autosubmit the form when the captcha was send

前端 未结 2 544
小鲜肉
小鲜肉 2021-01-20 17:52

I want to use ReCaptcha to load some extra data on the page. I want the form to be auto submitted when the ReCaptcha was entered. So that I don\'t need the extra submit butt

2条回答
  •  终归单人心
    2021-01-20 18:18

    That's sounds like an interesting technique. It would cut down on the clicking and key strokes for the user. Here is how you could do that, by listening for the successful captcha response you would be able to follow up with the desired action. Here is an example and some documentation. https://developers.google.com/recaptcha/docs/display#example

    var RC2KEY = 'sitekey';
    
    function reCaptchaVerify(response) {
      if (response === document.querySelector('.g-recaptcha-response').value) {
        document.forms['form-name'].submit();
      }
    }
    
    function reCaptchaExpired() {
      /* do something when it expires */
    }
    
    function reCaptchaCallback() {
      grecaptcha.render('id', {
        'sitekey': RC2KEY,
        'callback': reCaptchaVerify,
        'expired-callback': reCaptchaExpired
      });
    }

提交回复
热议问题