simialbi / yii2-visualcaptcha
Visual captcha implementation for yii2 framework
Installs: 300
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 2
Open Issues: 0
Language:JavaScript
Type:yii2-extension
Requires
- php: >=8.1
- simialbi/yii2-simialbi-base: >=0.13.1 <1.0 | ^1.0.0
- yiisoft/yii2: ^2.0.15
Requires (Dev)
- phpunit/phpunit: ^9.5.21
- yiisoft/yii2-coding-standards: ~2.0
Suggests
- ext-openssl: Needed in captcha component in utilRandomHex method if yii method fails
README
Resources
- visualCaptcha
- yii2 framework
Installation
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require --prefer-dist simialbi/yii2-visualcaptcha
or add
"simialbi/yii2-visualcaptcha": "*"
to the require
section of your composer.json
Usage
Setup Module
Add the module visualcaptcha
to the modules and bootstrap section of your configuration file:
[ 'bootstrap' => ['log', 'visualcaptcha'], 'modules' => [ 'visualcaptcha' => [ 'class' => 'simialbi\yii2\visualcaptcha\Module' ] ] ]
Example Usage
Define Model
<?php namespace app\models; use simialbi\yii2\visualcaptcha\validators\VisualCaptchaValidator; use yii\base\Model; class MyForm extends Model { public $name; public $email; public $subject; public $body; public $verifyCode; /** * {@inheritdoc} */ public function rules() { return [ [['name', 'email', 'subject', 'body', 'verifyCode'], 'required'], ['email', 'email'], ['verifyCode', VisualCaptchaValidator::class] ]; } }
Use in view
<?php use simialbi\yii2\visualcaptcha\widgets\VisualCaptcha; use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\MyForm */ $this->title = 'Visual Captcha'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="my-visualcaptcha"> <?php $form = ActiveForm::begin(['id' => 'test-form']); ?> <?=$form->field($model, 'name')->textInput(['autofocus' => true]);?> <?=$form->field($model, 'email');?> <?=$form->field($model, 'subject');?> <?=$form->field($model, 'body')->textarea(['rows' => 6]);?> <?=$form->field($model, 'verifyCode')->widget(VisualCaptcha::class, [ 'numberOfImages' => 10, 'clientOptions' => [ // change templates 'templates' => [ 'button' => ' <div class="visualCaptcha-{class}-button"> <a href="javascript:;"> <img src="{path}{class}{retinaExtra}.png" title="{classTitle}" alt="{classAlt}"> </a> </div>', 'buttonGroup' => ' <div class="visualCaptcha-button-group"> {btnRefresh} {btnAccessibility} </div>' ] ] ]);?> <div class="form-group"> <?=Html::submitButton('Submit', ['class' => ['btn', 'btn-primary']]);?> </div> <?php ActiveForm::end(); ?> ?> </div>
License
yii2-visualcaptcha is released under MIT license. See bundled LICENSE for details.