reCAPTCHA Contact is a Grav v0.9.33+ plugin that adds a contact form in Grav pages with Google reCAPTCHA validation to filter Spam Robots and includes multilanguage support. Currently English (en), Italian (it), Spanish (es), German (de), and Russian (ru) translations are included by default in the languages.yaml
.
reCAPTCHA Contact is fully integrated with the Grav admin panel, can be completely controlled through the plugin settings, and can be displayed by simply enabling the form on any page.
Install the plugin by going to the admin panel, selecting "Plugins", and then click the "Add" button in the upper right. Filter for reCAPTCHA Contact
and install.
- Go to Google Recaptcha, login, and get your recaptcha v2 keys.
- Back in Grav, go to the Plugins page again and click
reCAPTCHA Contact
. - Enter the site key and secret key in the correct fields.
- Choose a page to put the form on and select the "Contact Form" tab.
- Enable the contact form and put your email address in the "Send Emails To" field.
- Test and enjoy!
Installing the plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:
bin/gpm install recaptchacontact
This will install the reCAPTCHA Contact
plugin into your /user/plugins
directory within Grav. Its files can be found under /your/site/grav/user/plugins/recaptchacontact
.
To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins
. Then, rename the folder to recaptchacontact
. You can find these files either on GetGrav.org or the reCAPTCHA Contact GitHub repo.
You should now have all the plugin files under
/your/site/grav/user/plugins/recaptchacontact
NOTE: This plugin is a modular component for Grav which requires Grav, the Error and Problems plugins, and a theme to be installed in order to operate. It also requires having at least an outgoing mailserver on your server side (to send the emails) and a reCAPTCHA API key for your site.
The plugin comes with some sensible default configuration that you can see in the recaptchacontact.yaml
and languages.yaml
files of the plugin, that are pretty self explanatory:
enabled: (true|false) // Enables or Disables the entire plugin for all pages.
default_lang: en // default_lang in case there is no multilang support in the installation
disable_css: (false|true) // Enables or Disables the built-in default stylesheet
inject_template: (true|false) // If false, you will need to include the `recaptchaform.html.twig` in your templates
grecaptcha_sitekey: "your reCAPTCHA site key" // override in your /user/config/plugins/recaptchacontact.yaml
grecaptcha_secret: "secret-g-recaptcha-key" // override in your /user/config/plugins/recaptchacontact.yaml and remember not to keep it in a public repository
WARNING: For the reCAPTCHA to work you have to copy recaptchacontact.yaml in your
/user/config/plugins
folder and set your keys. If not, it will not work.
RECAPTCHACONTACT:
FORM_LEGEND: "Contact me" // Form Legend
SUBJECT: "New contact from Grav site!" // Subject for email.
RECIPIENT: "hello@example.com" // Email address.
FIELDS: // Default fields, you can translate the text.
NAME:
LABEL: "Name"
PLACEHOLDER: "Add your name"
EMAIL:
LABEL: "Email"
PLACEHOLDER: "Add your email"
MESSAGE:
LABEL: "Message"
PLACEHOLDER: "Add your message"
ANTISPAM:
LABEL: "Antispam"
PLACEHOLDER: "Please leave this field empty for Antispam"
SUBMIT:
LABEL: "Submit"
MESSAGES: // Default messages, you can translate the text.
SUCCESS: "Thank You! Your message has been sent."
ERROR: "Oops! There was a problem with your submission. Please complete the form and try again."
FAIL: "Oops! Something went wrong and we couldn't send your message."
If you want to add your own translations of the languages.yaml
variables or modify the existing ones you can do so by creating a languages
folder in your user
folder and creating a .yaml
file for the languages you want (ex. es.yaml
) adding the above variables to the file and customizing their values.
If you want to add the contact form to a page or modular page your can do it by adding to the page header:
---
title: 'My "Page"'
recaptchacontact: true
---
# "Lorem ipsum dolor sit amet"
With this method you use the config file and languages file options (either the default ones or your customized ones if they exist). This will add the contact form at the end of the contents of your page.
But if you want to overwrite any of the configuration variables (including those in the recaptchacontact/languages.yaml
you can also do it in the page header as in:
---
title: 'My "Page"'
recaptchacontact:
form_legend: "Another legend for the form"
subject: "Another subject form the email"
recipient: "anotheremail@example.com"
fields:
name:
label: "Another label for name"
placeholder: "Another placeholder for mail"
submit:
label: "Another Submit Label"
messages:
success: "Hurray! You did it!"
---
# "Lorem ipsum dolor sit amet"
Just use the same structure as in the languages.yaml
file but use lowercase letters instead of uppercase.
If you want to position the form in your template files manually, set inject_template
to false
(see above), and add the following to any templates that you want it to display in:
{% include 'partials/recaptchaform.html.twig' with {'page': page, 'recaptchacontact': recaptchacontact} %}
You can also easily override partials/recaptcha_container.html.twig
to adjust the layout of the HTML surrounding the form.
To override the default styling, do the following:
- Set
disable_css
totrue
. (This doesn't disable all CSS. It simply tells the program not to use the built-in CSS that comes with the plugin.) - Copy
recaptchacontact.css
from the plugin'sassets
folder into your theme'sassets
folder. - Edit as you see fit.
As development for this plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating this plugin is easy, and can be done through Grav's GPM system, as well as manually.
The simplest way to update this plugin is via the Grav Package Manager (GPM). You can do this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:
bin/gpm update recaptchacontact
This command will check your Grav install to see if your plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type y
and hit enter. The plugin will automatically update and clear Grav's cache.
Manually updating this plugin is pretty simple. Here is what you will need to do to get this done:
- Delete the
your/site/user/plugins/recaptchacontact
directory. - Download the new version of the plugin from either GetGrav.org or the reCAPTCHA Contact GitHub repo.
- Unzip the zip file in
your/site/user/plugins
and rename the resulting folder torecaptchacontact
. - Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing
bin/grav clear-cache
.
Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in
user/config/plugins
) will remain intact.
- @nunopress: For the Simple Contact plugins in which this one is based.
- @iusvar: For the Italian translation.
- @Sommerregen: For the German translation.
- @bassplayer7: Added the ability to customize almost everything in the plugin very easily.
- @ktaranov: For the Russian translation.
- @Perlkonig: For making it easier to customize the CSS.