bariew/yii2-invisible-recaptcha

Validates form post with Goolge Invisible Recaptcha

Installs: 10 013

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 4

Open Issues: 1

Type:yii2-extension

0.0.3 2019-02-08 10:32 UTC

This package is auto-updated.

Last update: 2024-04-16 14:12:33 UTC


README

Validates your ActiveForm using Google invisible-recaptcha

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist bariew/yii2-invisible-recaptcha "*"

or add

"bariew/yii2-invisible-recaptcha": "*"

to the require section of your composer.json file.

Usage

  1. Set application config params:
    'params' => [
    ...
        'invisible-recaptcha-key' => '<Your Key>',
        'invisible-recaptcha-secret'  => '<Your Secret>'
    ]
  1. 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'],
        ];
    }
  1. 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'],
    ]); ?>