我正在尝试创建我使用验证码的注册表。我已经启用了ejax验证。但是有一个问题,验证码第一次不能工作。当我生成新的captcha代码时,它就可以工作了。我的代码是:
在模型中,
public $verifyCode;
public function rules()
{
return array(
array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(), 'on'=>'registration'),
array('id, first_name,last_name, email, username, password, password_repeat, user_type, keystring, status, logo_url, last_login_time, create_time, update_time, validation', 'safe', 'on'=>'search'),
);
}在控制器中:
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'testLimit'=>3,
),
);
}视图中:
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha', array('captchaAction'=>'user/captcha')); ?>
</div>
<div class="formfieldarea">
<div class="form-text"></div>
<div class="form-field">
<?php echo $form->textField($model,'verifyCode'); ?>
<div class="hint">Please enter the letters as shown.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
</div>
<?php endif; ?>为了找到解决方案,我在谷歌上搜索了很多次。但是没有找到。请帮帮我。
发布于 2014-03-16 00:53:19
作为一个建议,在您的视图中执行如下操作:
<script type="text/javascript">
function captchaInit(){
$("#yw0_button").click();
}
</script>然后,在你的身体中onload调用这个函数。
<body onload="captchaInit()"> 它会导致在body load中重新加载验证码。在类似的情况下,它会在每次页面刷新时刷新验证码。
https://stackoverflow.com/questions/22422940
复制相似问题