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

1.0.4 2018-09-14 05:09 UTC

This package is not auto-updated.

Last update: 2024-03-16 17:34:52 UTC


README

Latest Stable Version Latest Unstable Version License

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 use
  • name - name of the Spam Guard form field
  • title - title of the Spam Guard form field
  • insertBefore - insert the Spam Guard form field before a field with this name
  • insertAfter - 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 protection
  • getDefaultName() - answers the default name for the form field
  • getDefaultTitle() - 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

Maintainers

Colin Tucker Praxis Interactive
Colin Tucker Praxis Interactive

License

BSD-3-Clause © Praxis Interactive