correct way to verify recaptcha with javascript??

242 views
Skip to first unread message

Tom Lyczko

unread,
Feb 25, 2019, 2:15:54 PM2/25/19
to reCAPTCHA
I have the following recaptcha code, it renders properly but people can just ignore it, how do I prevent this??

        <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>
        </script>
           
                <script type="text/javascript">
      var onloadCallback = function() {
        grecaptcha.render('html_element', {
          'sitekey' : '6LcTUpMUAAAAAO44eeAXAIAd9rDUprTP91J1kTLk'
        });
      };
   
      /*
                    $("#submit-form").click(function () {              
      var rcres = grecaptcha.getResponse();
          if(rcres.length){
            grecaptcha.reset();
            alert("Form Submitted!");
          }else{
            alert("Please verify reCAPTCHA");
          }
       */
    </script>
             <div id="html_element"></div>

        <p class="Submit">
            <input type="submit" id="submit-form" value="%%LNG_AuthorizeNetPayForOrder%%" />
        </p>
 

I cribbed this from a website, https://www.freakyjolly.com/add-recaptcha-v2-and-form-validation-using-custom-jquery/
The commented out part is removed because the captcha would not render with this code active, I do not know why.
I basically only need to verify they filled out the captcha, I know JS is not optimal for this but I have no access to server-side code.
We do load jQuery.at the top of the page.
I read about verifying the code but I don't understand it.
Reply all
Reply to author
Forward
0 new messages