riiitor / yii2-antispam

由CleanTalk提供的yii2反垃圾扩展,具有防止垃圾邮件机器人及手动垃圾邮件的功能

安装次数: 32

依赖者: 0

建议者: 0

安全性: 0

星星数: 0

关注者: 0

分支数: 4

类型:yii2-extension

v1.1.0 2019-07-08 13:52 UTC

This package is not auto-updated.

Last update: 2024-09-25 14:35:52 UTC


README

无需验证码,无需回答问题,无需计数动物,无需解谜,无需数学计算。

Build Status

##需求

Yii 2.0 或更高版本

##安装

安装此扩展的最佳方式是通过 composer

运行以下命令

php composer.phar require --prefer-dist cleantalk/yii2-antispam

或在您的composer.json文件的require部分添加以下内容

"cleantalk/yii2-antispam": "~1.0.0"

##使用方法

  1. https://cleantalk.org/register?platform=yii2 获取访问密钥

  2. 在protected/config/web.php中打开您的应用程序配置,并修改components部分

// application components
'components'=>[
    ...
        'antispam' => [
            'class' => 'cleantalk\antispam\Component',
            'apiKey' => 'Your API KEY',
        ],
    ...
],
  1. 在您的模型中添加验证器,例如 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'*/]
        ];
    }
}
  1. 在表单视图中添加隐藏的JavaScript检查小部件
<?php $form = ActiveForm::begin(); ?>
    ...
    <?= \cleantalk\antispam\Widget::widget()?>
    ...
    <?= Html::submitButton('Submit')?>
    ...
<?php ActiveForm::end(); ?>

用户注册验证器

查看 cleantalk\antispam\validators\UserValidator

示例规则

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'email'], 'required'],
            ['email', 'email'],
            ['email', UserValidator::className(), 'nickNameAttribute'=>'name']
        ];
    }

##许可证 GNU通用公共许可证

##资源