1.在controller中修改:
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, //显示为透明 ), );}
2.在view的form表单中添加如下代码:
labelEx($model,'verifyCode'); ?>widget('CCaptcha'); ?> textField($model,'verifyCode'); ?>Please enter the letters as they are shown in the image above.error($model,'verifyCode'); ?>
Letters are not case-sensitive.
3.如果想要检测 是否正确的话还要在相关的model类的rules方法中指定相关verifyCode的验证机制captcha,或者也可以通过调用CCaptchaValidator类的validate方法实现验证。