2016-05-17 13:58:17 3101次浏览 1条回答 1 悬赏 15 金钱

验证码错误

  • 1.本来是正确的,但是我开启了'enableAjaxValidation' => true,'enableClientValidation' => true,这两个之后,填写完验证码是没有错误提示的,但是当我提交的时候显示验证码错误
  • 1.view部分
<?php $form = ActiveForm::begin([
				    'id' => 'form-register',
				    'options' => ['class'=>'form-inline'],
				    'enableAjaxValidation' => true,
				    'enableClientValidation' => true,
				]);?>
				
				<?= $form->field($model,'username')->textInput(['autofocus'=>true]); ?><br/>
				
				<?= $form->field($model,'password')->passwordInput(); ?><br/>
				
				<?= $form->field($model,'repassword')->passwordInput(); ?><br/>
				
				<?= $form->field($model,'email')->textInput(); ?><br/>
				
				<?= $form->field($model,'sex')->inline()->radioList(['1'=>'男','2'=>'女']); ?><br/>
				
				<?= $form->field($model,'verifyCode')->widget(Captcha::className(),['captchaAction'=>'index/captcha','imageOptions'=>['id'=>'captchaimg', 'title'=>'换一个', 'alt'=>'换一个', 'style'=>'cursor:pointer;'],'template'=>'{input}{image}']) ?><br/>
				
				<div class="form-group">
                    <?= Html::submitButton('注册', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
                </div>
                
                <div class="form-group">
                    <?= Html::a('登录', ['index/login'], ['class' => 'btn btn-primary']) ?>
                </div>
                
				<?php ActiveForm::end();?>
  • 2.控制器部分
public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
                'maxLength' => 4,
                'minLength' => 3,
                'padding' => 5,
                'height' => 40,
                'offset' => 4,
                
            ],
        ];
    }
  • 3.model部分
    public function rules()
    {
        return [
            ['username', 'filter', 'filter' => 'trim'],
            [['username','password','repassword','email','sex'], 'required'],
            ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => '用户名已注册!'],
            ['username', 'string', 'min' => 6, 'max' => 16],
            ['username', 'match','pattern'=>'/^[(\x{4E00}-\x{9FA5})a-zA-Z]+[(\x{4E00}-\x{9FA5})a-zA-Z_\d]*$/u','message'=>'用户名由字母,汉字,数字,下划线组成,且不能以数字和下划线开头。'],

            ['email', 'filter', 'filter' => 'trim'],
            ['email', 'email'],
            ['email', 'string', 'max' => 255],
            ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => '邮箱已注册!'],
            
            ['sex','double','min'=>'1','max'=>'2','message'=>'性别不合法!'],
            
            [['password','repassword'], 'string', 'min' => 6 , 'max' => 18 , 'message' => '密码长度位6-18位!'],
            ['repassword','compare','compareAttribute' => 'password','message'=>'两次输入的密码不一致!'],
            
            ['verifyCode','captcha','captchaAction'=>'index/captcha']
您需要登录后才可以回答。登录 | 立即注册
lk1069319346
职场新人

lk1069319346

注册时间:2016-04-08
最后登录:2016-07-19
在线时长:5小时39分
  • 粉丝0
  • 金钱10
  • 威望0
  • 积分60

热门问题