How can I make reCAPTCHA a required field?

前端 未结 7 1283
闹比i
闹比i 2020-12-01 05:34

I\'m using Google reCAPTCHA and have been able to add the CAPTCHA component to my page inside a form. But when I submit the form there\'s no validation taking place to check

7条回答
  •  再見小時候
    2020-12-01 05:59

    If you want a more friendly and descriptive message, you can add a required checkbox. This will ensure the html5 popup shows something like: "Please check this box if you want to proceed"

    Add the code to remove the fake captcha once completed

    window.removeFakeCaptcha = function() {
       document.querySelector('.captcha-fake-field').remove();
    }
    

    Then on the css you hide the checkbox and position it to the captcha box:

    .captcha {
      position: relative;
    }
    .captcha-fake-field {
      background: transparent;
      bottom: 0;
      border: none;
      display: block;
      height: 1px;
      left: 12px;
      width: 1px;
      position: absolute;
      z-index: -1;
    }
    

提交回复
热议问题