用户模型:
public function rules()
{
return array(
...
array('verifyCode', 'captcha', 'on'=>'register'),
...
);
}
UserController中
public function actionRegister()
{
$model=new User;
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save()){
$this->redirect(array('login'));
}
}
...
$this->render('register');
}
查看 - register.php
<?php $this->widget('CCaptcha'); ?>
<div class="captcha"><?php echo CHtml::activeTextField( $model,'verifyCode', array('class'=>'captcha')); ?></div>
<?php echo $form->error($model,'verifyCode'); ?>
这会使验证码正常,但验证不会发生。可能是什么问题?
答案 0 :(得分:3)