Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在yii wform中添加验证码_Php_Yii_Captcha - Fatal编程技术网

Php 如何在yii wform中添加验证码

Php 如何在yii wform中添加验证码,php,yii,captcha,Php,Yii,Captcha,我正在对表单使用“wForm”扩展。我想在表格中添加“验证码”。 我试过用“myCaptcha”组件来表示“cForm”。 但是我得到了以下错误 “WForm”及其行为没有名为“MyCaptcha”的方法或闭包 如何在wForm中使用“cform验证码”?下载扩展名 1) 将CaptchaExtended.zip文件解压缩到../protected/extensions/CaptchaExtended/ 2) 注册CaptchaExtendedAction和CaptchaExtendedVali

我正在对表单使用“wForm”扩展。我想在表格中添加“验证码”。 我试过用“myCaptcha”组件来表示“cForm”。 但是我得到了以下错误

“WForm”及其行为没有名为“MyCaptcha”的方法或闭包

如何在wForm中使用“cform验证码”?

下载扩展名

1) 将CaptchaExtended.zip文件解压缩到../protected/extensions/CaptchaExtended/

2) 注册CaptchaExtendedAction和CaptchaExtendedValidator的类路径,例如在components/controller.php中:

public function init(){
    // register class paths for extension captcha extended
    Yii::$classMap = array_merge( Yii::$classMap, array(
        'CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedAction.php',
        'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedValidator.php'
    ));
}
3) 在控制器中定义操作,例如SiteController:

public function actions(){
    return array(
        'captcha'=>array(
            'class'=>'CaptchaExtendedAction',
            // if needed, modify settings
            'mode'=>CaptchaExtendedAction::MODE_MATH,
        ),
    );
}
4) 在模型::规则()中定义客户端验证:

5) 在视图文件中添加以下内容(在表单中)

public function rules(){
    return array(
        array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements()),
    );
}
$this->widget('CCaptcha'); //for captch image
echo CHtml::activeTextField($model,'verifyCode'); //text field to enter captcha text