控制器代码
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF, //背景颜色
'minLength'=>4, //最短为4位
'maxLength'=>4, //是长为4位
'transparent'=>true, //显示为透明
),
);
}
如果采用Ajax验证方法出现验证码出错的情况可以在最后加入
'testLimit'=>999, //这里可以设置大一些,以免验证超过三次会出错.
VIEW
<?php if(extension_loaded('gd')): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha',array('clickableImage'=>true,'showRefreshButton'=>false)); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
</div>
<?php endif; ?>