dev-master
9999999-devYii2 Google reCAPTCHA widget
MIT
The Requires
by sashsvamir
yii2 captcha google widget recaptcha
Yii2 Google reCAPTCHA widget
Widget to render google recaptcha and validate this field., (*1)
This implementaion allow to use: - multiple widgets on one page - also you can load page by ajax several times, (*2)
, (*3)
Now this widget extends himiklab/yii2-recaptcha-widget extension (automatic loading as depends in composer.json), (*4)
Just add extension to composer require section:, (*5)
composer require sashsvamir/yii2-recaptcha-widget:"dev-master"
, (*6)
Setup recaptcha config common/config/main.php
:, (*7)
'components' => [ // ... 'reCaptcha' => [ 'name' => 'reCaptcha', 'class' => 'sashsvamir\yii2\recaptcha\ReCaptcha', 'siteKey' => '<your site public key>', 'secret' => '<your site private key>', ], ],
To debug, use follow keys:, (*8)
'siteKey' => '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI', 'secret' => '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe',
see: https://developers.google.com/recaptcha/docs/faq, (*9)
Add ReCaptchaValidator in your model, for example:, (*10)
public $verifyCode; public function rules() { return [ // ... ['verifyCode', ReCaptchaValidator::className(), 'uncheckedMessage' => 'Please confirm that you are not a bot.', // add follow lines to prevent checking recaptcha when from has errors 'when' => function ($model) { return !$model->hasErrors(); } ], ]; }
$form->field($model, 'verifyCode')->widget(\sashsvamir\yii2\recaptcha\ReCaptcha::className())->label(false);
Yii2 Google reCAPTCHA widget
MIT
yii2 captcha google widget recaptcha