PHPackages                             websvc/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. [Security](/categories/security)
4. /
5. websvc/yii2-recaptcha-widget

ActiveYii2-extension[Security](/categories/security)

websvc/yii2-recaptcha-widget
============================

Yii2 Google reCAPTCHA v2 and v3 widget

2.1.1.2(4y ago)022MITPHP

Since Jun 10Pushed 4y agoCompare

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

READMEChangelogDependencies (1)Versions (15)Used By (0)

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

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

Based on Google reCaptcha API 2.0 and 3.0.

**NOTE**: This is a fork of  @v2.1.1

The original project seems stalled, and there's some issues that needed some attention, hence the fork

Any versions released from this repo should follow the following mask for tags 2.1.1.x

If there are any updates upstream it should be able to accommodate those changes and cope with upstream versions.

---

![Packagist](https://camo.githubusercontent.com/ab84f520d57e54bae8420f237cf460f7a6b3cc0182ca8caa8542cd30f1210f34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765627376632f796969322d7265636170746368612d7769646765742e737667) ![Packagist](https://camo.githubusercontent.com/ea751f630ce226a529dc9d20c256a2b0a6d4b6bbea159138d0d2de1c3ed973c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765627376632f796969322d7265636170746368612d7769646765742e737667) ![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 "websvc/yii2-recaptcha-widget" "*"

```

or add

```
"websvc/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' => 'websvc\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' => [
        websvc\yii2\recaptcha\ReCaptcha2::className() => function ($container, $params, $config) {
            return new websvc\yii2\recaptcha\ReCaptcha2(
                'your siteKey v2',
                '', // default
                $config
            );
        },
        websvc\yii2\recaptcha\ReCaptchaValidator2::className() => function ($container, $params, $config) {
            return new websvc\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'], \websvc\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'], \websvc\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

```
