PHPackages                             ferrumfist/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. ferrumfist/yii2-recaptcha-widget

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

ferrumfist/yii2-recaptcha-widget
================================

Yii2 Google reCAPTCHA widget

1.2.1.2(7y ago)0893MITPHP

Since Jun 10Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (12)Used By (0)

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

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

Based on reCaptcha API 2.0.

![Packagist](https://camo.githubusercontent.com/5ae6a7596c1b364917139a624c5589eaa3d198674913cec02134416d356ce9a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f66657272756d666973742f796969322d7265636170746368612d7769646765742e737667) ![Packagist](https://camo.githubusercontent.com/255dcd40ecaad381db67e21d85592a81fc1380629b889ebc562e521ad1e4ccad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66657272756d666973742f796969322d7265636170746368612d7769646765742e737667) ![license](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)

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

[](#installation)

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

- Either run

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

```

or add

```
"ferrumfist/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#createsite).
- 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' => [
        'name' => 'reCaptcha',
        'class' => 'ferrumfist\yii2\recaptcha\ReCaptcha',
        'siteKey' => 'your siteKey',
        'secret' => 'your secret key',
    ],
    ...
```

- Add `ReCaptchaValidator` in your model, for example:

```
public $reCaptcha;

public function rules()
{
  return [
      // ...
      [['reCaptcha'], \ferrumfist\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'your secret key', 'uncheckedMessage' => 'Please confirm that you are not a bot.']
  ];
}
```

or just

```
public function rules()
{
  return [
      // ...
      [[], \ferrumfist\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'your secret key']
  ];
}
```

or simply

```
public function rules()
{
  return [
      // ...
      [[], \ferrumfist\yii2\recaptcha\ReCaptchaValidator::className()]
  ];
}
```

Usage
-----

[](#usage)

For example:

```
