yii widget验证码不实用form验证的方法

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('验证码错误'));
}

posted @ 2015-08-25 15:27  liangyeyue  阅读(141)  评论(0编辑  收藏  举报