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

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

iamsaint/yii2-recaptcha-widget
==============================

Yii2 Google reCAPTCHA widget

1.0.0(9y ago)02.8k↓100%1MITPHP

Since Dec 21Pushed 9y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

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

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

Based on reCaptcha API 2.0.

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

[](#installation)

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

- Either run

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

```

or add

```
"iamsaint/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' => 'iamsaint\yii2\recaptcha\ReCaptcha',
        'siteKey' => 'your siteKey',
        'secret' => 'your secret key',
    ],
    ...
```

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

```
public $reCaptcha;

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

or just

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

or simply

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

Usage
-----

[](#usage)

For example:

```
