controller:
public function actions() {
return array(
'verify' => array(
'class' => 'application.components.widgets.HCaptchaAction',
'testLimit' => 999,
'backColor' => 0xFFFFFF,
'maxLength' => '4', // 最多生成几个字符
'minLength' => '4', // 最少生成几个字符
'height' => '30',
'width'=>80
),
);
}
view:
<?php $this->widget('CCaptcha', array('showRefreshButton'=>false, 'captchaAction'=>'verify','clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图','title'=>'点击换图','id'=>"verify_code"))); ?>
验证方法:
if(!$this->createAction('verify')->validate($_POST['User']['verify_value'] ,false)){
exit(json_encode('验证码错误'));
}