Yii2 reCAPTCHA widget., (*1)
Installation
Composer
The preferred way to install this extension is through Composer., (*2)
Either run, (*3)
php composer.phar require gbksoft/yii2-recaptcha-widget "*"
, (*4)
or add, (*5)
"gbksoft/yii2-recaptcha-widget": "*"
, (*6)
to the require section of your composer.json, (*7)
Usage
Register a new site., (*8)
Add captcha attribute to model:, (*9)
public $captcha;
public function rules()
{
return [
[
'captcha',
\gbksoft\recaptcha\validators\RecaptchaValidator::class,
'secret' => '<your-secret>'
]
];
}
Add field to view:, (*10)
<?= $form->field($model, 'captcha')->widget(\gbksoft\recaptcha\widgets\Recaptcha::class, [
'clientOptions' => [
'data-sitekey' => '<your-sitekey>'
]
]) ?>
Info
See reCAPTCHA documentation, (*11)