A form spam protection module for SilverStripe v4.
Installation is via Composer:
$ composer require silverware/spam-guard
As with all SilverStripe modules, configuration is via YAML. An extension to the base Form
class is
applied via config.yml
. Configuration is also used to define the default Spam Guard instance via the
SilverStripe dependency injector:
SilverStripe\Core\Injector\Injector:
DefaultSpamGuard:
class: SilverWare\SpamGuard\Guards\SimpleSpamGuard
The default instance SimpleSpamGuard
uses a honeypot approach for preventing spam, combined with a minimum form
submission time, defined by the timeLimit
property.
Once installed, you can enable simple spam protection on your forms by using the following code:
$form = Form::create( ... );
if ($form->hasMethod('enableSpamProtection')) {
$form->enableSpamProtection();
}
By using hasMethod
to check for the spam protection method, instead of hasExtension
,
we enable interoperability between this extension and the SilverStripe SpamProtection extension
with no changes required to the form code.
The enableSpamProtection
method accepts an optional array of arguments with the following keys:
class
- class of the Spam Guard instance to usename
- name of the Spam Guard form fieldtitle
- title of the Spam Guard form fieldinsertBefore
- insert the Spam Guard form field before a field with this nameinsertAfter
- insert the Spam Guard form field after a field with this name
For example:
if ($form->hasMethod('enableSpamProtection')) {
$form->enableSpamProtection([
'class' => CustomSpamGuard::class,
'name' => 'CustomSpamGuard'
'title' => 'Tasty Spam',
'insertAfter' => 'Message'
]);
}
Spam Guard instances must implement the SilverWare\SpamGuard\Interfaces\SpamGuard
interface. Your
implementation must include the following methods:
getFormField()
- answers the form field responsible for spam protectiongetDefaultName()
- answers the default name for the form fieldgetDefaultTitle()
- answers the default title for the form field
Please use the GitHub issue tracker for bug reports and feature requests.
Your contributions are gladly welcomed to help make this project better. Please see contributing for more information.
- Inspired by the SilverStripe SpamProtection module.
Colin Tucker | Praxis Interactive |
BSD-3-Clause © Praxis Interactive