easedevs/yii2-turnstile-validator

Yii2 validator for Cloudflare's Turnstile CAPTCHA alternative

Installs: 1 220

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Type:yii2-extension

v1.0.2 2023-11-22 02:23 UTC

This package is auto-updated.

Last update: 2024-04-22 03:16:24 UTC


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],
        ];
    }
}