2017 © Pedro Peláez
 

library spam-bundle

Provides spam protection for Symfony3 forms

image

isometriks/spam-bundle

Provides spam protection for Symfony3 forms

  • Friday, September 23, 2016
  • by isometriks
  • Repository
  • 6 Watchers
  • 23 Stars
  • 24,807 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 5 Forks
  • 5 Open issues
  • 9 Versions
  • 8 % Grown

The README.md

Symfony SpamBundle

Please feel free to send pull requests. I would like to incorporate a bunch of spam methods into this project., (*1)

Installation

Install via Composer:, (*2)

$ composer require isometriks/spam-bundle

If you're not using Symfony Flex, add the bundle to your config/bundles.php file:, (*3)

// config/bundles.php

return [
    // ...
    Isometriks\Bundle\SpamBundle\IsometriksSpamBundle::class => ['all' => true],
];

Currently we have:, (*4)

Timed Spam Prevention

Requires forms to be sent after a certain amount of time. Most bots won't wait to submit your forms, so requiring an amount of time between render and submit can help deter these bots., (*5)

A side affect of this spam prevention is that you won't be able to refresh a page to resubmit data UNLESS the view is rendered again $form->createView() This is because the event listener removes the start time of the form and when it can't find it, will cause the form to be invalid. You could set your min time to 0 to just make use of this feature, (*6)

Also note that this spam protection will also apply this limit to forms that are not filled in correctly and need to be resubmitted. A high minimum time could affect those users who only need to fix one field quickly, (*7)

Configuration:, (*8)

# config/packages/isometriks_spam.yaml

# Copying this config is not necessary. These are defaults, only copy 
# what you'd like to change. 
isometriks_spam:
    timed:
        min: 7 # seconds
        max: 3600
        global: false
        # message also takes translator strings.
        message: You're doing that too quickly.

Usage:, (*9)

$this->createForm(MyType:class, null, [
    'timed_spam' => true, // Just this line is required to enable this feature, the rest is to override settings
    'timed_spam_min' => 3,
    'timed_spam_max' => 40,
    'timed_spam_message' => 'Please wait 3 seconds before submitting',
]);

Or, (*10)

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'timed_spam' => true,
        // ...
    ]);
}

Honeypot Spam Prevention

A honeypot is a way to trick bots into filling out a field that should not be filled out. It is hidden and can be named something usual so that any bots / crawlers will think it is a real field., (*11)

If the field is filled out, then the form is invalid. You can optionally choose to use a class name to hide the form element as well in case the bot tries to check the style attribute., (*12)

# Copying this config is not necessary. These are defaults, only copy 
# what you'd like to change. 
isometriks_spam:
    honeypot:
        field: email_address
        use_class: false
        hide_class: hidden
        global: false
        message: Form fields are invalid

Usage:, (*13)

// Only honeypot = true is required to enable, the rest are to override settings
$this->createForm(MyType::class, null, [
    'honeypot' => true,
    'honeypot_field' => 'email_address',
    'honeypot_use_class' => false,
    'honeypot_hide_class' => 'hidden',
    'honeypot_message' => 'Form fields are invalid',
]);

Or, (*14)

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'honeypot' => true,
        // ...
    ]);
}

Twig Form Error Message Rendering

Form errors come from the form itself, so if you want to display the errors you'll need to make sure this is in your template., (*15)

{% if form.vars.errors is not empty %}
    {{ form_errors(form) }}
{% endif %}

The Versions

23/09 2016

dev-master

9999999-dev

Provides spam protection for Symfony3 forms

  Sources   Download

symfony3 spam

23/09 2016

v1.0.0

1.0.0.0

Provides spam protection for Symfony3 forms

  Sources   Download

symfony3 spam

10/02 2016

dev-symfony-2

dev-symfony-2

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

10/02 2016

v0.3.2

0.3.2.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

12/06 2015

v0.3.1

0.3.1.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

03/06 2015

v0.3.0

0.3.0.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

18/07 2013

0.2.2

0.2.2.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

18/07 2013

0.2.1

0.2.1.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam

16/07 2013

0.2.0

0.2.0.0

Provides spam protection for Symfony2 forms

  Sources   Download

symfony2 spam