cleantalk / yii2-antispam
Anti-spam yii2 extension by CleanTalk with protection against spam bots and manual spam
Installs: 17 590
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 4
Forks: 5
Open Issues: 1
Type:yii2-extension
pkg:composer/cleantalk/yii2-antispam
Requires
- cleantalk/php-antispam: ~2.0.0
Requires (Dev)
- phpunit/phpunit: ~4.6.9
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2025-10-11 12:21:18 UTC
README
Anti-spam extension for the Yii2 framework powered by the CleanTalk API.
Invisible protection from spam bots on contact, comment, and registration forms — no reCAPTCHA, no puzzles, no delays.
Features
- Works invisibly in the background (no user interaction required)
- Blocks spam bots using CleanTalk’s multi-layered checks
- reCAPTCHA-free UX — no puzzles, images, or questions
- Easy integration into Yii2 forms and models
- Supports contact forms, comment forms, and registration forms
Requirements
- Yii 2.0 or above
- CleanTalk account https://cleantalk.org/register?product=anti-spam
##Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist cleantalk/yii2-antispam
or add
"cleantalk/yii2-antispam": "~1.0.0"
to the require section of your composer.json.
##Usage
- 
Get access key on https://cleantalk.org/register?platform=yii2 
- 
Open your application configuration in protected/config/web.php and modify components section: 
// application components
'components'=>[
    ...
        'antispam' => [
            'class' => 'cleantalk\antispam\Component',
            'apiKey' => 'Your API KEY',
        ],
    ...
],
- Add validator in your model, for example ContactForm:
namespace app\models;
use cleantalk\antispam\validators\MessageValidator;
use Yii;
use yii\base\Model;
/**
 * ContactForm is the model behind the contact form.
 */
class ContactForm extends Model
{
    public $name;
    public $email;
    public $body;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            // name, email, subject and body are required
            [['name', 'email', 'subject', 'body'], 'required'],
            // email has to be a valid email address
            ['email', 'email'],
            ['body', MessageValidator::className(), 'emailAttribute'=>'email', /*'nickNameAttribute'=>'name'*/]
        ];
    }
}
- In form view add widget for hidden Javascript checks:
<?php $form = ActiveForm::begin(); ?>
    ...
    <?= \cleantalk\antispam\Widget::widget()?>
    ...
    <?= Html::submitButton('Submit')?>
    ...
<?php ActiveForm::end(); ?>
User registration validator
See cleantalk\antispam\validators\UserValidator
Example rules:
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'email'], 'required'],
            ['email', 'email'],
            ['email', UserValidator::className(), 'nickNameAttribute'=>'name']
        ];
    }
##License GNU General Public License
##Resources