Google Recaptcha V2 with Serverside PHP

I thought this might be helpful to anyone trying to use Recatcha V2 in Webflow with a serverside PHP script for form handling. Once you sign up for Recaptcha V2 on Google’s site, you must add an embed element to your Webflow form to hold the Google code snippet. Google says to give the element a class name of ‘g-recaptcha’ but I noticed that Webflow appends ’ w-embed’ to the class name behind the scenes. This prevents the Recaptcha widget from appearing in your form. Here is what I did to get this to work:

  1. Add an embed element to your Webflow form where you want the Recaptcha widget to appear.
  2. Give the embed element a class name of ‘g-recaptcha w-embed’.
  3. Paste the Google code snippet into the embed element, and edit the code by changing the class name from ‘g-recaptcha’ to ‘g-recaptcha w-embed’, and entering your SiteKey.
  4. Edit the page (gear icon) and paste the following code inside the head tag:
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>

The widget should now appear in your form (Note: You can add ‘YourSite.webflow.io’ to your Recaptcha settings in Google to make testing easier).

Next you’ll need to modify the PHP script that handles the form processing. I found the following link very helpful:

(https://www.kaplankomputing.com/blog/tutorials/recaptcha-php-demo-tutorial/)

I hope this helps!

2 Likes

Thanks mjcasa! I’m super ignorant about how PHP scripts work but I have a real need for a recaptcha on my forms so is there any way you can help me understand how to use PHP in this context? Do I need to have special coding skills or use a host other than Webflow? Thanks in advance.

Jason

I cant get this to work correctly.

I’m lost on #3 Paste the Google code snippet into the embed element, and edit the code by changing the class name from ‘g-recaptcha’ to ‘g-recaptcha w-embed’, and entering your SiteKey.

Where do i enter my site key?

You can also try this link: https://itsolutionstuff.com/post/php-how-to-implement-google-new-recaptcha-code-example-with-demoexample.html It might be help you.

This link might help you
https://www.codecheef.org/article/laravel-9-google-recaptcha-v3-step-by-step-tutorial

You can also try this article to implement your logic Integration of Google reCaptcha v2 in PHP. It will help you.