PHP code example of jlorente / yii2-enhanced-captcha
1. Go to this page and download the library: Download jlorente/yii2-enhanced-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/ */
//.../config/main.php
return [
// ... other configurations ...
'modules' => [
// list of modules,
'captcha' => [
'class' => 'jlorente\captcha\Module',
'cache' => [
'class' => 'yii\caching\ApcCache',
// ... other configurations for the cache component ...
]
// ... other configurations for the module ...
]
],
'bootstrap' => [
//other modules to bootstrap,
'captcha'
]
];
//.../config/main.php
return [
// ... other configurations ...
'modules' => [
// list of modules,
'captcha' => [
'class' => 'jlorente\captcha\Module',
'cache' => [
'class' => 'yii\caching\ApcCache',
// ... other configurations for the cache component ...
],
'duration' => 100, //In seconds
'requestNumber' => 3
// ... other configurations for the module ...
]
],
'bootstrap' => [
//other modules to bootstrap,
'captcha'
]
];
//.../config/main.php
return [
// ... other configurations ...
'modules' => [
// list of modules,
'captcha' => [
'class' => 'jlorente\captcha\Module',
'cache' => [
'class' => 'yii\caching\ApcCache',
// ... other configurations for the cache component ...
],
'duration' => 100, //In seconds
'requestNumber' => 3,
'captchaAction' => [
'class' => CaptchaAction::className(),
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
// ... other configurations for the captcha action ...
]
// ... other configurations for the module ...
]
],
'bootstrap' => [
//other modules to bootstrap,
'captcha'
]
];
//.../models/MyModel.php
use jlorente\captcha\CaptchaValidator;
class MyModel extends \yii\base\Model {
public $id;
public $name;
public $captcha;
public function rules() {
return [
[['id', 'name'], '
//.../views/mymodel/create.php
use jlorente\captcha\Captcha;
$form = ActiveForm::begin([
'id' => 'my-form',
]);
echo $form->field($this->model, 'id');
echo $form->field($this->model, 'name');
echo $form->field($this->model, 'captcha', [
'template' => "{input}\n{hint}\n{error}"
])->widget(Captcha::className());
// In this example the template attribute is provided to the ActiveField in order to hide the label of the captcha attribute.
bash
$ php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.