PHPackages                             alexeevdv/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. alexeevdv/yii2-recaptcha-widget

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

alexeevdv/yii2-recaptcha-widget
===============================

Google reCAPTCHA widget for Yii2

1.2.1(6y ago)452.1k↓36%5[1 issues](https://github.com/alexeevdv/yii2-recaptcha-widget/issues)[1 PRs](https://github.com/alexeevdv/yii2-recaptcha-widget/pulls)MITPHP

Since Jan 25Pushed 5y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (4)Versions (11)Used By (0)

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

[](#yii2-recaptcha-widget)

[![Build Status](https://camo.githubusercontent.com/aad6d246d43ebd6ddb5673981d7338e300e23657aa93b5c683825d26d941ae69/68747470733a2f2f7472617669732d63692e6f72672f616c657865657664762f796969322d7265636170746368612d7769646765742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alexeevdv/yii2-recaptcha-widget)[![codecov](https://camo.githubusercontent.com/3bcd88df48815e3c99dae3275caa71f15efb7c67c3f592206a1825a9eaf83628/68747470733a2f2f636f6465636f762e696f2f67682f616c657865657664762f796969322d7265636170746368612d7769646765742f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/alexeevdv/yii2-recaptcha-widget)[![PHP 5.6](https://camo.githubusercontent.com/02377f76b3cbe5c9bd3bc047522682376deaab69a4aed013b4a00018e068db72/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d677265656e2e737667)](https://camo.githubusercontent.com/02377f76b3cbe5c9bd3bc047522682376deaab69a4aed013b4a00018e068db72/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d677265656e2e737667)[![PHP 7.0](https://camo.githubusercontent.com/28174979e725b1f51a3ddc2a37022bd139e49d42f64fdc7b9322b3e5a15a3f7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d677265656e2e737667)](https://camo.githubusercontent.com/28174979e725b1f51a3ddc2a37022bd139e49d42f64fdc7b9322b3e5a15a3f7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d677265656e2e737667)[![PHP 7.1](https://camo.githubusercontent.com/89830e985e0a7f5f1ed58d412d81ee5bdccafb5dd5861eb9a6e63e44dde568b6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e312d677265656e2e737667)](https://camo.githubusercontent.com/89830e985e0a7f5f1ed58d412d81ee5bdccafb5dd5861eb9a6e63e44dde568b6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e312d677265656e2e737667)[![PHP 7.2](https://camo.githubusercontent.com/047bbe011ab372b4d00fc7ab0ed6f0d2a3db1ffda3a25de65f318dac100328ba/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e322d677265656e2e737667)](https://camo.githubusercontent.com/047bbe011ab372b4d00fc7ab0ed6f0d2a3db1ffda3a25de65f318dac100328ba/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e322d677265656e2e737667)[![PHP 7.3](https://camo.githubusercontent.com/ebdf47db6e91607cc8e1a8ea16f4a35122a068c1e3a23b9eb6c9932d602d28ff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332d677265656e2e737667)](https://camo.githubusercontent.com/ebdf47db6e91607cc8e1a8ea16f4a35122a068c1e3a23b9eb6c9932d602d28ff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e332d677265656e2e737667)

Yii2 wrapper for Google [reCAPTCHA](https://www.google.com/recaptcha).

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

[](#installation)

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

Either run

```
$ php composer.phar require alexeevdv/yii2-recaptcha-widget "^1.0"
```

or add

```
"alexeevdv/yii2-recaptcha-widget": "^1.0"

```

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

Configuration
-------------

[](#configuration)

### Through application component

[](#through-application-component)

```
'components' => [
    //...
    'recaptcha' => [
        'class' => \alexeevdv\recaptcha\Recaptcha::class,
        'siteKey' => 'YOUR_SITE_KEY',
        'secret' => 'YOUR_SECRET',
    ],
    //...
],
```

### Through widget and validator params

[](#through-widget-and-validator-params)

```
use alexeevdv\recaptcha\RecaptchaValidator;
use alexeevdv\recaptcha\RecaptchaWidget;

// Model validation rules
public function rules()
{
    return [
        //...
        [
            ['recaptcha'],
            RecaptchaValidator::class,
            'secret' => 'YOUR_SECRET',
            'minimalScore' => 0.6,
            'onScoreReceived' => function ($score) {
                // Do smth on actual user score. F.e. log it somewhere
            },
        ],
        //...
    ];
}

// Widget params
echo RecaptchaWidget::widget([
    'siteKey' => 'YOUR_SITE_KEY',
]);
```

Usage
-----

[](#usage)

```
use alexeevdv\recaptcha\RecaptchaValidator;
use alexeevdv\recaptcha\RecaptchaWidget;

// Using ActiveForm
// In this case model validation rules will be applied
// You'll need to specify RecaptchaValidator for attribute
echo $form->field($model, 'recaptcha')->widget(RecaptchaWidget::class);

// As standalone field
echo RecaptchaWidget::widget(['name' => 'recaptcha']);
// In this case you need to check value manually
$validator = new RecaptchaValidator();
$isValid = $validator->validateValue(Yii::$app->request->get('recaptcha'));
```

Usage in tests
--------------

[](#usage-in-tests)

To turn off recaptcha checking you need to add this in your test config:

```
'container' => [
    'definitions' => [
        \alexeevdv\recaptcha\RecaptchaValidator::class => ['skipOnEmpty' => true],
    ],
],

```

Additional component and widget params
--------------------------------------

[](#additional-component-and-widget-params)

```
/**
 * Optional. Color theme of the widget. "dark" or "light"
 * @var string
 */
public $theme;

/**
 * Optional. The type of CAPTCHA to serve. "image" or "audio"
 * @var string
 */
public $type;

/**
 * Optional. The size of the widget. "compact" or "normal"
 * @var string
 */
public $size;

/**
 * Optional. The tabindex of the widget and challenge.
 * If other elements in your page use tabindex, it should be set to make user navigation easier.
 * @var integer
 */
public $tabindex;

/**
 * Optional. The name of your callback function, executed when the user submits a successful response.
 * The g-recaptcha-response token is passed to your callback.
 * @var string|JsExpression
 */
public $callback;

/**
 * Optional. The name of your callback function, executed when the reCAPTCHA response expires
 * and the user needs to re-verify.
 * @var string|JsExpression
 */
public $expiredCallback;

/**
 * Optional. The name of your callback function, executed when reCAPTCHA encounters an error
 * (usually network connectivity) and cannot continue until connectivity is restored. If you specify
 * a function here, you are responsible for informing the user that they should retry.
 * @var string|JsExpression
 */
public $errorCallback;

/**
 * Optional. Forces the widget to render in a specific language
 * If not set then language is auto detected from application language
 * If set to false then language is autodetected on client side
 */
public $language;
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 91.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~129 days

Recently: every ~149 days

Total

9

Last Release

2367d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e6f71682c6a273973ad9c29d60ddac6d3cc55db7e55ec4f5638115f4c22409f6?d=identicon)[alexeevdv](/maintainers/alexeevdv)

---

Top Contributors

[![alexeevdv](https://avatars.githubusercontent.com/u/597839?v=4)](https://github.com/alexeevdv "alexeevdv (42 commits)")[![jaddek](https://avatars.githubusercontent.com/u/10332802?v=4)](https://github.com/jaddek "jaddek (2 commits)")[![moplin](https://avatars.githubusercontent.com/u/9134990?v=4)](https://github.com/moplin "moplin (1 commits)")[![tibee](https://avatars.githubusercontent.com/u/3636947?v=4)](https://github.com/tibee "tibee (1 commits)")

---

Tags

recaptchawidgetyii2yii2-extensionyii2-widgetsgooglerecaptchacaptchayii2widget

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/alexeevdv-yii2-recaptcha-widget/health.svg)

```
[![Health](https://phpackages.com/badges/alexeevdv-yii2-recaptcha-widget/health.svg)](https://phpackages.com/packages/alexeevdv-yii2-recaptcha-widget)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
