Search code examples
phpwordpresscontact-form-7

How is it possible to trigger recaptcha v3 (score test) every time a user clicks on a submit button in contact from 7


I have followed the steps in contact form 7 and its working fine but I want to trigger it automatically every time a user clicks on the submit button rather than Google judging by itself who is a bot and prompting the test for bots only


Solution

  • To trigger reCaptcha on a button, you simply need to bind the captcha to a button.

    <button class="g-recaptcha" data-sitekey="yourKey" data-callback="onSubmit">Submit</button>
    

    then add "onSubmit" function to handle reCaptcha's response.

    <script type="text/javascript">
      var onSubmit = function(response) {
        document.getElementById("simpleForm").submit(); // send response to your backend service
      };
    </script>
    

    Reference from https://product.hubspot.com/blog/quick-guide-invisible-recaptcha