我的 YII 项目中有验证码问题。我在弹出表单中包含了一个验证码。它显示正确,但验证存在问题。验证有时是正确的,如果我们第一次尝试输入正确的单词,验证说它是错误的,在生成另一个代码后验证成功。为什么?
在模型-> 规则中:
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'on'=> 'signup')
在控制器中 -> 通过 renderPartial 调用注册表单
$this->renderPartial('signUp',array('model'=>$model),false,true);
鉴于:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'sign-up-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
-----------------------
-----------------------
<?php if(CCaptcha::checkRequirements()): ?>
<?php echo $form->labelEx($model, 'verifyCode', array('for'=>'User_security_code')); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode',array('class'=>'txt-style width-289')); ?>
Please enter the letters as they are shown in the image above. Letters are not case-sensitive.
<?php echo $form->error($model,'verifyCode',array('class'=>'error_msg')); ?>
<?php endif; ?>