This bundle provides some basic features to reduce spam in symfony.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require core23/antispam-bundle
Then, enable the bundle by adding it to the list of registered bundles in bundles.php
file of your project:
// config/bundles.php
return [
// ...
Core23\AntiSpamBundle\Core23AntiSpamBundle::class => ['all' => true],
];
Create a form on the fly:
$this->createForm(CustomFormType:class, null, array(
// Time protection
'antispam_time' => true,
'antispam_time_min' => 10,
'antispam_time_max' => 60,
// Honeypot protection
'antispam_honeypot' => true,
'antispam_honeypot_class' => 'hide-me',
'antispam_honeypot_field' => 'email-repeat',
));
{# Replace plain text #}
{{ text|antispam }}
{# Replace rich text mails #}
{{ htmlText|antispam(true) }}
If you want a JavaScript decoding for the encoded mails, you should use the AntiSpam.js
library:
$(document).ready(function () {
new AntiSpam('.custom_class');
});
It is recommended to use webpack / webpack-encore
to include the JavaScript library in your page. These file is located in the assets
folder.
Add protection to all forms using the configuration:
# config/packages/core23_antispam.yaml
core23_antispam:
# Time protection
time:
global: true
# Honeypot protection
honeypot:
global: true
Create a configuration file called core23_antispam.yaml
:
# config/packages/core23_antispam.yaml
core23_antispam:
# Twig mail filter
twig:
mail:
css_class: 'custom_class'
at_text: [ '[DOT]', '(DOT)', '[.]' ]
dot_text: [ '[AT]', '(AT)', '[ÄT]' ]
# Time protection
time:
min: 5
max: 3600
global: false
# Honeypot protection
honeypot:
field: 'email_address'
class: 'hidden'
global: false
provider: 'core23_antispam.provider.session'
It is recommended to use webpack / webpack-encore
to include the AntiSpam.js
file in your page. These file is located in the assets
folder.
This bundle is under the MIT license.