Hello Grav community,
I’m experiencing an issue with setting up Google reCAPTCHA for the contact form on my site. I’ve configured the form plugin with the correct site key and secret key, and I’ve tried using both the v2 (checkbox) and v3 versions of reCAPTCHA.
When I use the v2 checkbox, I can see the checkbox appear on the form, and with v3, I see the badge on the screen. However, when I submit the form, I always get the error message: “Captcha not valid.”
Here’s the form.md
file for my contact page:
title: Contact Form
form:
name: contact
fields:
name:
label: Name
placeholder: Enter your name
autocomplete: on
type: text
validate:
required: true
email:
label: Email
placeholder: Enter your email address
type: email
validate:
required: true
message:
label: Message
placeholder: Enter your message
type: textarea
validate:
required: true
g-recaptcha-response:
label: Captcha
type: captcha
recaptcha_not_validated: 'Captcha not valid!'
validate:
required: true
buttons:
submit:
type: submit
value: Submit
reset:
type: reset
value: Reset
process:
captcha: true
save:
fileprefix: contact-
dateformat: Ymd-His-u
extension: txt
body: "{% include 'forms/data.txt.twig' %}"
email:
subject: "[Site Contact Form] {{ form.value.name|e }}"
body: "{% include 'forms/data.html.twig' %}"
message: Thank you for getting in touch!