PHPackages                             overplex/yii2-recaptcha-widget - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. overplex/yii2-recaptcha-widget

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

overplex/yii2-recaptcha-widget
==============================

Yii2 Google reCAPTCHA v2 and v3 widget

2.1.1(6y ago)0348MITPHP

Since Jun 10Pushed 10mo agoCompare

[ Source](https://github.com/overplex/yii2-recaptcha-widget)[ Packagist](https://packagist.org/packages/overplex/yii2-recaptcha-widget)[ RSS](/packages/overplex-yii2-recaptcha-widget/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (13)Used By (0)

Google reCAPTCHA widget for Yii2
================================

[](#google-recaptcha-widget-for-yii2)

Based on Google reCaptcha API 2.0 and 3.0.

![Packagist](https://camo.githubusercontent.com/83201da43276c3eab531a2b24ac6216c6f4b4fbb08639e25a1040462dd1bce5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68696d696b6c61622f796969322d7265636170746368612d7769646765742e737667) ![Packagist](https://camo.githubusercontent.com/aa8dcb6f174837e3f66f2594ad15ad016e8cc4c57ffdb954c27ab2adfa2531f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68696d696b6c61622f796969322d7265636170746368612d7769646765742e737667) ![license](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)

Upgrade to 2.x version
----------------------

[](#upgrade-to-2x-version)

Warning! Classes `ReCaptcha` and `ReCaptchaValidator` is deprecated. Please replace their to `ReCaptchaConfig`, `ReCaptcha2` and `ReCaptchaValidator2`.

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

[](#installation)

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

- Either run

```
php composer.phar require --prefer-dist "overplex/yii2-recaptcha-widget" "*"

```

or add

```
"overplex/yii2-recaptcha-widget" : "*"
```

to the `require` section of your application's `composer.json` file.

- [Sign up for an reCAPTCHA API keys](https://www.google.com/recaptcha/admin/create).
- Configure the component in your configuration file (web.php). The parameters siteKey and secret are optional. But if you leave them out you need to set them in every validation rule and every view where you want to use this widget. If a siteKey or secret is set in an individual view or validation rule that would overrule what is set in the config.

```
'components' => [
    'reCaptcha' => [
        'class' => 'himiklab\yii2\recaptcha\ReCaptchaConfig',
        'siteKeyV2' => 'your siteKey v2',
        'secretV2' => 'your secret key v2',
        'siteKeyV3' => 'your siteKey v3',
        'secretV3' => 'your secret key v3',
    ],
    ...
```

or use DI container:

```
'container' => [
    'definitions' => [
        himiklab\yii2\recaptcha\ReCaptcha2::className() => function ($container, $params, $config) {
            return new himiklab\yii2\recaptcha\ReCaptcha2(
                'your siteKey v2',
                '', // default
                $config
            );
        },
        himiklab\yii2\recaptcha\ReCaptchaValidator2::className() => function ($container, $params, $config) {
            return new himiklab\yii2\recaptcha\ReCaptchaValidator2(
                'your secret key v2',
                '', // default
                null, // default
                null, // default
                $config
            );
        },
    ],
],
```

- Add `ReCaptchaValidator2` or `ReCaptchaValidator3` in your model, for example:

v2

```
public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator2::className(),
        'secret' => 'your secret key', // unnecessary if reСaptcha is already configured
        'uncheckedMessage' => 'Please confirm that you are not a bot.'],
  ];
}
```

v3

```
public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator3::className(),
        'secret' => 'your secret key', // unnecessary if reСaptcha is already configured
        'threshold' => 0.5,
        'action' => 'homepage',
      ],
  ];
}
```

Usage
-----

[](#usage)

For example:

v2

```
