Google Recaptcha not working

Melody Scott
Melody Scott used Ask the Experts™
on
I added google recapcha 2 to this form: https://www.magickitchen.com/contact.html
I thought I had it working, by adding this code below. I thought I could do it all client side. But I just realized that I can complete the form without checking the box. I obviously need a function, the one given in the example was alert("grecaptcha is ready!");

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
</script>
<script type="text/javascript">
  var onloadCallback = function() {
   
  };
</script>

https://developers.google.com/recaptcha/docs/display  I obviously am missing a big part here. Help!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
sharjeel ashrafSenior Network Engineer

Commented:
just checked it and it works fine, attached is a screen shot.
Hi,

you should use v3 instead of v2
https://www.google.com/recaptcha/intro/v3.html

A lot of bots are able to bypass v2, so it better to take a few minutes and adapt your code to v3
https://developers.google.com/recaptcha/docs/v3

also don't forget to add some css to recaptcha container for responsive ...

Author

Commented:
Hi, all. I can submit the form without entering the captcha, so I really don't think it's working right.

I looked at captcha version 3, and since I can't seem to get 2 working, I doubt I can get that working. Can we focus on v2, since that was my question? It's just a contact form, I just want to keep a few bots away.

Thanks!
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hi, folks, we're getting way too much spam on this, so I am going back to the old validation method, and will create a new page for us to test the google recaptcha. Please give me twenty minutes or so to provide a new link. Thanks.

Author

Commented:
Ok, let's please work on this page: https://www.magickitchen.com/contact-recaptcha.html

As you can see, if I enter the form without clicking the recaptcha checkmark, the form submits. I have nothing set up on the server, what you see on this page is all.
sharjeel ashrafSenior Network Engineer

Commented:
i would check your data site key is correct.
 if so try to generate another one.

Author

Commented:
ok. So as far as you can tell, the page is set up correctly?

Author

Commented:
I checked the site key and it was correct. I tried adding this as the function: grecaptcha.execute();  so now the javascript section reads:

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
</script>
<script type="text/javascript">
  var onloadCallback = function(grecaptcha.execute();) {
   
  };
</script>
 But still I can submit the form without using the recaptcha checkbox.

Author

Commented:
I tried this as well, added this in the head per: https://developers.google.com/recaptcha/docs/display, but I could still sumbit the form without checking the captcha

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
</script>
    <script>
        var onSubmit = function(token) {
          console.log('success!');
        };

        var onloadCallback = function() {
          grecaptcha.render('submit', {
            'sitekey' : 'usedmysitekey',
            'callback' : onSubmit
          });
        };
    </script>

Author

Commented:
Hi, all, this is the advice I needed, it works now: https://artisansweb.net/validate-google-recaptcha-using-javascript/
Hi,

I would recommend to validate using server side method (using PHP)
Never rely on JavaScript validation as it can be bypassed by user / bots.

Author

Commented:
Right you are, lenamtl, it didn't keep the spambots away.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial