when i input captcha code to text box correct, but this allway send me captcha incorrect
pls help me.
My Englis is bad
My controller
<?php
namespace frontend\controllers;
use frontend\models\BodyForm;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
class LeechController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => [ 'index'],
'rules' => [
[
'actions' => ['index'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionIndex()
{
//return $this->render('index');
$model = new BodyForm();
if ($model->load(Yii::$app->request->post() && $model->validate())) {
Yii::$app->session->setFlash('success', 'Demo body ^^');
return $this->render('body',['model' => $model]);
}
else{
return $this->render('body',['model' => $model]);
}
}
}
?>
My Models
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
Class BodyForm extends Model
{
public $body;
public $verifyCode;
public function rules()
{
return [
[['body'],'required'],
['verifyCode', 'captcha'],
];
}
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
'body' => 'Message',
];
}
}
?>
View
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ContactForm */
$this->title = 'Demo Messages';
$this->params['breadcrumbs'][] = $this->title;
?>
<h1><?= Html::encode($this->title) ?></h1>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'body-form']); ?>
<?= $form->field($model, 'body') ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'captchaAction'=>'body/captcha',
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'body-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>