easedevs / yii2-turnstile-validator
Yii2 validator for Cloudflare's Turnstile CAPTCHA alternative
Installs: 2 114
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ^2.0
- yiisoft/yii2-httpclient: *
Requires (Dev)
- phpunit/phpunit: ^9.5
README
Yii2 validator for Cloudflare's Turnstile CAPTCHA alternative
Installation
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require "easedevs/yii2-turnstile-validator" "*"
or add
"easedevs/yii2-turnstile-validator": "*"
to the require
section of your composer.json
file.
In your config, add a component configuration:
'turnstile' => [ 'class' => 'easedevs\yii2\turnstile\TurnstileConfig', 'siteKey' => '_YOUR_SITE_KEY_FROM_CLOUDFLARE_TURNSTILE_', 'secret' => '_YOUR_SECRET_FROM_CLOUDFLARE_TURNSTILE_', ],
Usage
Using as an ActiveField
widget:
use easedevs\yii2\turnstile\TurnstileInput; echo $form->field($model, 'captcha')->widget(TurnstileInput::class, [ 'size' => TurnstileInput::SIZE_COMPACT, ]);
Using as a simple widget:
use easedevs\yii2\turnstile\TurnstileInput; echo TurnstileInput::widget([ 'name' => 'captcha', 'size' => TurnstileInput::SIZE_COMPACT, ]);
Using validator in a model for verification of the result on the server:
use easedevs\yii2\turnstile\TurnstileInputValidator; class Account extends Model { public $captcha; public function rules() { return [ [['captcha'], 'string'], [['captcha'], TurnstileInputValidator::class], ]; } }