Google recaptcha v3 recaptcha_response is null

后端 未结 1 1887
终归单人心
终归单人心 2021-01-27 10:20

i am using google recaptcha v3 in my website ,

here is the code i have added in my html web page in the head:

相关标签:
1条回答
  • 2021-01-27 11:13

    i tried lots of changes but everytime i get " token = null " then i try this.. 100% working....

    in Your Html

    <html>
    <head>
    </head>
    <body>
      <form id="contact">
        <div class="col-12">
          <div class="form-group">
              <input type="hidden" name="captcha_token" id="recaptchaResponse" data-sitekey="YOUR-SITE-KEY">
          </div>
        </div>
        <div class="col-12">
            <button type="submit" class="btn btn-lg" id="submit-btn">
                SUBMIT
            </button>
        </div>
      </form>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
      <script src="https://www.google.com/recaptcha/api.js?onload=ReCaptchaCallbackV3&render=YOUR-SITE-KEY"></script>
    </body>
    </html>

    after then add in your js file

    $(document).ready(function(){
      setInterval(function(){
            ReCaptchaCallbackV3();    
        }, 90000);
        
        $(document).on("submit",'#contact',function (e) {
          var token = $('[name="g-recaptcha-response"]').val();
          console.log(token);
        });
    });
    
    var ReCaptchaCallbackV3 = function() {
        grecaptcha.ready(function () {
            grecaptcha.execute('YOUR-SITE-KEY', { action: 'contact' }).then(function (token) {});
        });
    }

    0 讨论(0)
提交回复
热议问题