Yii2 invisible recaptcha component
Validates your ActiveForm using Google invisible-recaptcha, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist bariew/yii2-invisible-recaptcha "*"
or add, (*4)
"bariew/yii2-invisible-recaptcha": "*"
to the require section of your composer.json
file., (*5)
Usage
- Set application config params:
'params' => [
...
'invisible-recaptcha-key' => '<Your Key>',
'invisible-recaptcha-secret' => '<Your Secret>'
]
- Add verification attribute and a validation rule into your model rules:
public $verifyCode;
/**
* @inheritdoc
*/
public function rules()
{
return [
...
['verifyCode', InvisibleRecaptchaValidator::className(), 'message' => 'Invalid captcha value'],
];
}
- Use widget instead of ActiveForm submit button in your view:
<?= $form->field($model, 'verifyCode')->widget(\bariew\invisibleRecaptcha\InvisibleRecaptchaWidget::className(), [
'buttonText' => 'Save' ,
'options' => ['class' => 'btn btn-primary'],
]); ?>