If you're using Google reCAPTCHA with custom code in Webflow instead of Webflow's built-in reCAPTCHA element, you must handle the secret key securely on the server side, not within Webflow.
1. Understand Where the Secret Key Goes
- The reCAPTCHA secret key must never be added to the frontend (i.e., Webflow’s custom code section) because it would be exposed in the browser.
- The secret key is used to verify the reCAPTCHA token after a user submits the form. This verification step must happen on a secure backend server.
2. Set Up a Server-Side Endpoint
- You need to create a backend endpoint (using platforms like Make (Integromat), Zapier with Webhooks, Firebase Functions, AWS Lambda, etc.).
- This endpoint should:
- Accept the reCAPTCHA token submitted from the client.
- Send a POST request to
https://www.google.com/recaptcha/api/siteverify
with:- secret: your reCAPTCHA secret key
- response: the token received from the client
- remoteip (optional): user's IP
- Add a hidden field to your Webflow form to carry the reCAPTCHA token (e.g.,
g-recaptcha-response
). - Use custom JavaScript (in the footer or embed code) to:
- Initialize reCAPTCHA
- Get a token using
grecaptcha.execute()
- Populate the hidden input field with the token before form submission
- Use a custom form action URL that submits data directly to your server or automation tool, rather than Webflow’s native form handler.
- Embed this via form
action
attribute override in the <head>
or using the Webflow Forms Plus tool.
5. Validate the Token Server-Side
- On your backend, receive the reCAPTCHA token and validate it using your secret key.
- Google will return a JSON response indicating success/failure.
- Use this result to determine whether to accept or reject the form submission.
Summary
To use reCAPTCHA with custom code, include your secret key only in the server-side verification logic—never in Webflow’s frontend. Create a backend endpoint to validate the reCAPTCHA response using the secret key securely and configure your Webflow form to send data to that endpoint.