https://github.com/cleantalk/yii2-antispam
Anit-spam extension for Yii2 framework.
https://github.com/cleantalk/yii2-antispam
anti-spam antispam php spam spam-prevention spam-protection yii yii2-extension yii2-framework
Last synced: 5 months ago
JSON representation
Anit-spam extension for Yii2 framework.
- Host: GitHub
- URL: https://github.com/cleantalk/yii2-antispam
- Owner: CleanTalk
- Created: 2015-06-03T05:33:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-16T03:02:53.000Z (7 months ago)
- Last Synced: 2025-04-24T18:05:28.098Z (6 months ago)
- Topics: anti-spam, antispam, php, spam, spam-prevention, spam-protection, yii, yii2-extension, yii2-framework
- Language: PHP
- Size: 14.6 KB
- Stars: 10
- Watchers: 5
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Anti-spam extension by CleanTalk for Yii2 framework.
No Captcha, no questions, no counting animals, no puzzles, no math.
[](https://travis-ci.org/cleantalk/yii2-antispam)
## 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](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist cleantalk/yii2-antispam
```or add
```json
"cleantalk/yii2-antispam": "~1.0.0"
```to the require section of your composer.json.
##Usage
1) Get access key on https://cleantalk.org/register?platform=yii2
2) 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',
],
...
],
```3) 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'*/]
];
}
}
```4) In form view add widget for hidden Javascript checks:
```
...
= \cleantalk\antispam\Widget::widget()?>
...
= Html::submitButton('Submit')?>
...```
## 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
* https://cleantalk.org/
* https://github.com/CleanTalk/yii2-antispam