demi / recaptcha
Yii2 wrapper for reCAPTCHA widget
Installs: 710
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- google/recaptcha: ~1.1
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-10-27 21:24:37 UTC
README
Yii2 wrapper for [reCAPTCHA](https://www.google.com/recaptcha/intro/index.html widget)
Installation
Run
composer require "demi/recaptcha" "~1.0"
Configurations
Register new reCAPTCHA API keys
Add keys to /common/config/params.php
:
return [ // reCAPTCHA API keys 'reCAPTCHA.siteKey' => 'xxxxxxxxx', 'reCAPTCHA.secretKey' => 'xxxxxxxxx', ];
In the form:
<?= $form->field($model, 'captcha', ['enableAjaxValidation' => false])->label(false) ->widget('demi\recaptcha\ReCaptcha', ['siteKey' => Yii::$app->params['reCAPTCHA.siteKey']]) ?>
In the model validation rules:
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; } ], }