2017 © Pedro Peláez
 

yii2-extension yii2-recaptcha

Google ReCaptcha v2.0 Yii 2.x.x extension

image

brussens/yii2-recaptcha

Google ReCaptcha v2.0 Yii 2.x.x extension

  • Friday, March 24, 2017
  • by brussens
  • Repository
  • 3 Watchers
  • 5 Stars
  • 1,068 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 21 % Grown

The README.md

Google ReCaptcha v2.0 Yii 2.x.x extension

Latest Stable Version Total Downloads License, (*1)

The main difference from the similar extensions is that this one doesn't require an application component with constant name, such as \Yii::$app->recaptcha or something., (*2)

Install

Either run, (*3)

php composer.phar require --prefer-dist brussens/yii2-recaptcha "*"

or add, (*4)

"brussens/yii2-recaptcha": "*"

to the require section of your composer.json file., (*5)

Add to your bootstrap file:, (*6)


$container->setSingleton(\ReCaptcha\ReCaptcha::class, function($container, $params, $config) { return new \ReCaptcha\ReCaptcha('your secret'); }); $container->set(\brussens\yii2\extensions\recaptcha\Widget::class, function($container, $params, $config) { return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config); });

Since Yii 2.0.11 you can also configure the container in the 'container' section of the app configuration:, (*7)

'container' => [
    'definitions' => [
        \brussens\yii2\extensions\recaptcha\Widget::class => function($container, $params, $config) {
            return new \brussens\yii2\extensions\recaptcha\Widget('your site key', \Yii::$app->language, $config);
        }
    ],
    'singletons' => [
         \ReCaptcha\ReCaptcha::class => function($container, $params, $config) {
             return new \ReCaptcha\ReCaptcha('your secret');
         }
    ]
]

Add in your model validation rules, (*8)

public function rules()
{
    return [
        ...
        ['verifyCode', \brussens\yii2\extensions\recaptcha\Validator::className()],
        ...
    ];
}

Add in your view, (*9)

echo $form->field($model, 'verifyCode')->widget(\brussens\yii2\extensions\recaptcha\Widget::className());

If you use Pjax or multiple widgets on page, (*10)

echo $form->field($model, 'verifyCode')->widget(
    \brussens\yii2\extensions\recaptcha\Widget::className(), [
    'options' => [
        'id' => 'insert-unique-widget-id'
    ]
]);

The Versions

24/03 2017

dev-master

9999999-dev

Google ReCaptcha v2.0 Yii 2.x.x extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Brusensky Dmitry

yii2 yii google recaptcha

27/01 2017

1.0.0

1.0.0.0

Google ReCaptcha v2.0 Yii 2.x.x extension

  Sources   Download

MIT

The Requires

 

by Brusensky Dmitry

yii2 yii google recaptcha