PHP code example of denis909 / yii2-captcha

1. Go to this page and download the library: Download denis909/yii2-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

denis909 / yii2-captcha example snippets




use denis909\yii\captcha\Captcha;

echo $form->field($model, 'verifyCode')->widget(Captcha::className(), [
	'captchaAction' => '/site/captcha',
	'options' => [
		'class' => 'form-control'
	],					
	'attribute2' => 'verifyCode2',
	'attribute2Options' => [
		'class' => $model->hasErrors('verifyCode') 
			? 'form-control ' . $form->errorCssClass 
			: 'form-control'
	],				
	'containerTag' => 'div',
	'containerOptions' => [
		'class' => 'row gutters-xs'
	],					
	'imageContainerTag' => 'div',
	'imageContainerOptions' => [
		'class' => 'col-xs-3',
		'style' => 'min-width: 164px;'
	],
	'attributeContainerTag' => 'div',
	'attributeContainerOptions' => [
		'class' => 'col-xs-2',
		'style' => 'padding-right: 0px;'
	],
	'devider' => '&mdash;',
	'deviderTag' => 'div',
	'deviderOptions' => [
		'class' => 'col-xs-1',
		'style' => 'padding-top: 15px; text-align: center;'
	],
	'attribute2ContainerTag' => 'div',
	'attribute2ContainerOptions' => [
		'class' => 'col-xs-2',
		'style' => 'padding-left: 0px;'
	]
]);

public function actions()
{
    return [
        'captcha' => [
            'class' => 'denis909\yii\captcha\CaptchaAction',
            'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            'testLimit' => 10,
            'width' => 150,
            'height' => 49,
            'offset' => 10,
            'minLength' => 5,
            'maxLength' => 5,
            'padding' => 0,
            'foreColor' => 0x4a4949,
            //'resetValidCaptcha' => false                
        ]
    ];
}

$captcha = $this->createAction('captcha');
	        
$captcha->reset();

public $verifyCode;

public $verifyCode2;

public function rules()
{
	return [
		[
			'verifyCode', 
			\denis909\yii\captcha\CaptchaValidator::className(), 
			'attribute2' => 'verifyCode2',
			'captchaAction' => '/site/captcha'
		]
	];
}