PHPackages                             wiperawa/yii2-recaptcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wiperawa/yii2-recaptcha

ActiveYii2-extension

wiperawa/yii2-recaptcha
=======================

116PHP

Since Jan 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/wiperawa/yii2-recaptcha)[ Packagist](https://packagist.org/packages/wiperawa/yii2-recaptcha)[ RSS](/packages/wiperawa-yii2-recaptcha/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-recaptcha
==============

[](#yii2-recaptcha)

Yii2 widget and model behavior for Google Recaptcha v3.

This widget and behavior allow you to easy add reCAPTCHA v3 (invisible reCAPTCHA) by Google into your project.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require wiperawa/yii2-recaptcha "dev-master"

```

or add

```
"wiperawa/yii2-recaptcha": "dev-master"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

1. First of all we need to add site in google reCAPTCHA [console](https://www.google.com/recaptcha/admin/)and get SECRET and SITE keys.
2. Then we have to configure behavior for model we use:

```
use wiperawa\recaptcha\GoogleRecaptchaBehavior;
...
class MyCoolModel extends ActiveRecord {
...
public function behaviors()
    {
        return [
            'googleRecaptchaBehavior' => [
                'class' =>GoogleRecaptchaBehavior::class,
                'secretKey' => 'Google reCAPTCHA Secret Key here',
                'enabled' => true, //Can omit this parameter. just in case you want to temporarily switch off recaptcha
                'expectedAction' => 'form_submit' //google reCAPTCHA expected action. action we expect from our form.
                'scoreThreshold' => 0.5 //reCAPTCHA score treshold. Optional. default - 0.5
            ],
        ];
    }
...
}
```

3. Now when we have behavior attached to our model, we need to add widget to ActiveForm :

```
use wiperawa\recaptcha\GoogleRecaptchaWidget;
...
