Spam protection module for SilverStripe CMS
Go to file
2017-08-28 13:20:19 +12:00
_config Add namespaces, separate test classes, add PSR-4 autoloader, update PSR-2 compliance 2017-08-28 13:19:03 +12:00
.tx Add transifex config 2015-05-26 17:14:40 +12:00
code Add namespaces, separate test classes, add PSR-4 autoloader, update PSR-2 compliance 2017-08-28 13:19:03 +12:00
images BUGFIX: Fixed replaced deprecated FieldSet() with FieldList() 2012-07-06 19:59:57 -03:00
lang Add namespaces, separate test classes, add PSR-4 autoloader, update PSR-2 compliance 2017-08-28 13:19:03 +12:00
tests Add namespaces, separate test classes, add PSR-4 autoloader, update PSR-2 compliance 2017-08-28 13:19:03 +12:00
_config.php SilverStripe 4 and Namespacing 2017-08-28 13:11:48 +12:00
.editorconfig Added standard editor config 2015-11-19 13:23:15 +13:00
.gitattributes Update usage examples in readme, minor fixes in travis configuration and gitattributes 2017-08-28 13:19:05 +12:00
.gitignore Ignore .DS_Store 2014-02-10 20:48:53 +13:00
.scrutinizer.yml Added standard Scrutinizer config 2015-11-21 19:27:50 +13:00
.travis.yml Update usage examples in readme, minor fixes in travis configuration and gitattributes 2017-08-28 13:19:05 +12:00
.upgrade.yml Add upgrader mapping file 2017-08-28 13:20:19 +12:00
changelog.md Update changelog for 2.0.4 release 2016-05-19 11:56:38 +12:00
code-of-conduct.md Added standard code of conduct 2015-11-21 20:11:25 +13:00
codecov.yml Update Travis configuration to be standalone, add codecov.io, update license year 2017-08-28 13:11:49 +12:00
composer.json FIX Add versioned to dev requirements 2017-08-28 13:19:39 +12:00
license.md Update Travis configuration to be standalone, add codecov.io, update license year 2017-08-28 13:11:49 +12:00
phpunit.xml.dist Update usage examples in readme, minor fixes in travis configuration and gitattributes 2017-08-28 13:19:05 +12:00
README.md Update usage examples in readme, minor fixes in travis configuration and gitattributes 2017-08-28 13:19:05 +12:00

SpamProtection Module

Build Status Code Coverage

Maintainer Contact

  • Saophalkun Ponlu <phalkunz (at) silverstripe (dot) com>

  • Will Rossiter <will (at) fullscreen (dot) io>

Requirements

SilverStripe 4.0 or greater

Documentation

This module provides a generic, consistent API for adding spam protection to your SilverStripe Forms. This does not provide any spam protection out of the box, for that, you must also download one of the spam protection implementations. Currently available options are:

As a developer you can also provide your own protector by creating a class which implements the SpamProtector interface. More on that below.

Configuring

After installing this module and a protector of your choice (i.e mollom) you'll need to rebuild your database through dev/build and set the default protector via SilverStripe's config system. This will update any Form instances that have spam protection hooks with that protector.

mysite/_config/spamprotection.yml

---
name: spamprotection
---
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
  default_spam_protector: MollomSpamProtector

To add spam protection to your form instance call enableSpamProtection.

// your existing form code
$form = new Form(/* .. */);
$form->enableSpamProtection();

The logic to perform the actual spam validation is controlled by each of the individual SpamProtector implementation since they each require a different implementation client side or server side.

Options

enableSpamProtection takes a hash of optional configuration values.

$form->enableSpamProtection(array(
    'protector' => MathSpamProtector::class,
    'name' => 'Captcha'
));

Options to configure are:

protector a class name string or class instance which implements SpamProtector. Defaults to your FormSpamProtectionExtension.default_spam_protector value.

name the form field name argument for the Captcha. Defaults to Catcha. title title of the Captcha form field. Defaults to '' insertBefore name of existing field to insert the spam protection field prior to mapping an array mapping of the Form fields to the standardized list of field names. The list of standardized fields to pass to the spam protector are:

title
body
contextUrl
contextTitle
authorName
authorMail
authorUrl
authorIp
authorId

Defining your own SpamProtector

Any class that implements SpamProtector and the getFormField() method can be set as the spam protector. The getFormField() method returns the FormField to be inserted into the Form. The FormField returned should be in charge of the validation process.

hasExtension(FormSpamProtectionExtension::class)) { $form->enableSpamProtection(); } ```