long399 / yii2-math-captcha
yii2 MathCaptchaAction
Package info
github.com/ProkopenkoRoman/yii2-math-captcha
Type:yii2-extension
pkg:composer/long399/yii2-math-captcha
Requires
- yiisoft/yii2: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
MathCaptchaAction for Yii Framework 2.0
Installation
The preferred way to install this extension is through composer. Either run
composer require --prefer-dist long399/yii2-math-captcha
or add
"long399/yii2-math-captcha": "~0.1"
to the require section of your composer.json file.
Available operations
- Addition.
- Subtraction.
- Multiplication.
Default addition or subtraction operation will be used randomly.
Usage
controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \long399\captcha\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, ], ... ]; }
model:
class MyModel extends \yii\db\ActiveRecord { public $captcha; ... public function rules() { return [ ... ['captcha', 'captcha', 'captchaAction' => '/site/captcha'], ... ]; } ... }
view:
... echo $form->field($model, 'captcha')->widget(\yii\captcha\Captcha::class, [ 'captchaAction' => "/site/captcha", 'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>', ]); ...
If you want to use only expressions with a subtraction operation e.g., then you need to set the operations property accordingly in the description of the action in the controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \app\components\actions\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, 'operations' => ['-'], ], ... ]; }
Expressions with multiplication
If you want to use also expressions with a multiplication operation, then you need to set the operations property accordingly in the description of the action in the controller:
public function actions() { return [ ... 'captcha' => [ 'class' => \app\components\actions\MathCaptchaAction::class, 'fixedVerifyCode' => YII_ENV_TEST ? '399' : null, 'minLength' => 0, 'maxLength' => 1000, 'operations' => ['+', '-', '*'], ], ... ]; }
Three kinds of expressions can be generated:
- Expression with multiplication.
- Expression with multiplication and addition.
- Expression with multiplication and subtraction.
Author
long399, e-mail: long399@mail.ru