Adds recaptcha-v3 into yii2 project
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist z1bun/yii2-module-recaptcha-v3 "dev-master"
or add
"z1bun/yii2-module-recaptcha-v3": "dev-master"
to the require section of your composer.json
file.
Once the extension is installed, simply use it in your code by :
add this to your components main.php
'components' => [
...
'reCaptcha3' => [
'class' => 'z1bun\recaptcha3\ReCaptcha',
'siteKey' => env('recaptcha_site_key'),
'secretKey' => env('recaptcha_secret_key'),
],
and in your model
acceptance_score the minimum score for this request (0.0 - 1.0) or null
public $reCaptcha;
public function rules()
{
return [
...
[['reCaptcha'], \z1bun\recaptcha3\ReCaptchaValidator::class, 'acceptance_score' => 0]
];
}
<?= $form->field($model, 'reCaptcha')->widget(\z1bun\recaptcha3\ReCaptchaWidget::class) ?>
When use YII_ENV_TEST
in index-test.php
then disabled recaptcha's validate:
defined('YII_ENV') or define('YII_ENV', 'test');
Option to hide the badge and display a link to recaptcha terms of use in the form