silverware / spam-guard
SilverWare Spam Guard Module.
Installs: 397
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- php: >=5.6.0
- silverstripe/framework: ^4@dev
This package is not auto-updated.
Last update: 2024-11-09 20:56:25 UTC
README
A form spam protection module for SilverStripe v4.
Contents
Requirements
Installation
Installation is via Composer:
$ composer require silverware/spam-guard
Configuration
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.
Usage
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.
Arguments
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' ]); }
Writing your own Spam Guard class
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
Issues
Please use the GitHub issue tracker for bug reports and feature requests.
Contribution
Your contributions are gladly welcomed to help make this project better. Please see contributing for more information.
Attribution
- Inspired by the SilverStripe SpamProtection module.
Maintainers
License
BSD-3-Clause © Praxis Interactive