demi/recaptcha

reCAPTCHA小部件的Yii2包装器

安装: 709

依赖项: 2

建议者: 0

安全: 0

星星: 0

关注者: 3

分支: 0

公开问题: 0

类型:yii2-extension

1.0.1 2015-08-03 10:55 UTC

This package is auto-updated.

Last update: 2024-08-27 20:55:38 UTC


README

Yii2包装器用于[reCAPTCHA](https://www.google.com/recaptcha/intro/index.html小部件)

安装

运行

composer require "demi/recaptcha" "~1.0"

配置

注册新的reCAPTCHA API密钥

将密钥添加到/common/config/params.php

return [
    // reCAPTCHA API keys
    'reCAPTCHA.siteKey' => 'xxxxxxxxx',
    'reCAPTCHA.secretKey' => 'xxxxxxxxx',
];

在表单中

<?= $form->field($model, 'captcha', ['enableAjaxValidation' => false])->label(false)
    ->widget('demi\recaptcha\ReCaptcha', ['siteKey' => Yii::$app->params['reCAPTCHA.siteKey']]) ?>

在模型验证规则中

public function rules()
{
    return [
        // captcha
        [
            ['captcha'], 'demi\recaptcha\ReCaptchaValidator', 'secretKey' => Yii::$app->params['reCAPTCHA.secretKey'],
            'when' => function ($model) {
                /** @var $model self */
                return !$model->hasErrors() && Yii::$app->user->isGuest;
            }
        ],
}