A spam protector and form field using the new Google's reCAPTCHA 2 aka No Captcha
A spam protector and form field using the new Google's reCAPTCHA 2 aka No Captcha.
- SilverStripe 4.x
- SilverStripe Spam Protection 3.x
- PHP CURL
composer require undefinedoffset/silverstripe-nocaptcha
After installing the module via composer or manual install you must set the spam protector to NocaptchaProtector, this needs to be set in your site's config file normally this is mysite/_config/config.yml.
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension: default_spam_protector: UndefinedOffset\NoCaptcha\Forms\NocaptchaProtector
There are multiple configuration options for the field, you must set the site_key and the secret_key which you can get from the reCAPTCHA page. These configuration options must be added to your site's yaml config typically this is mysite/_config/config.yml.
UndefinedOffset\NoCaptcha\Forms\NocaptchaField: site_key: "YOUR_SITE_KEY" #Your site key (required) secret_key: "YOUR_SECRET_KEY" #Your secret key (required) verify_ssl: true #Allows you to disable php-curl's SSL peer verification by setting this to false (optional, defaults to true) default_theme: "light" #Default theme color (optional, light or dark, defaults to light) default_type: "image" #Default captcha type (optional, image or audio, defaults to image) default_size: "normal" #Default size (optional, normal, compact or invisible, defaults to normal) default_badge: "bottomright" #Default badge position (bottomright, bottomleft or inline, defaults to bottomright) proxy_server: "" #Your proxy server address (optional) proxy_auth: "" #Your proxy server authentication information (optional)
If you want to add a field label or help text to the Captcha field you can do so like this:
$form->enableSpamProtection() ->fields()->fieldByName('Captcha') ->setTitle("Spam protection") ->setDescription("Please tick the box to prove you're a human and help us stop spam.");
When your using the silverstripe/comments module you must add the following (per their documentation) to your _config.php in order to use nocaptcha/spamprotection on comment forms.