如何在yii wform中添加验证码
How to add captcha in yii wform
我正在使用 "wForm" 表单扩展。我想在我的表单中添加 "captcha"。
我已经为 "cForm" 尝试了 "myCaptcha" 组件。
http://www.yiiframework.com/wiki/733/how-to-show-a-captcha-in-cform/
但我收到以下错误
"WForm" and its behaviors do not have a method or closure named "MyCaptcha".
如何使用 "cform captcha in wForm"?
下载扩展程序cCaptcha extension
1) 解压CaptchaExtended.zip个文件到../protected/extensions/captchaExtended/.
2) 注册 class 到 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) 在控制器中定义动作,例如网站管理员:
public function actions(){
return array(
'captcha'=>array(
'class'=>'CaptchaExtendedAction',
// if needed, modify settings
'mode'=>CaptchaExtendedAction::MODE_MATH,
),
);
}
4) 在model::rules():
中定义客户端验证
public function rules(){
return array(
array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
5) 在您的视图文件中添加以下内容(在您的表单中)
$this->widget('CCaptcha'); //for captch image
echo CHtml::activeTextField($model,'verifyCode'); //text field to enter captcha text
我正在使用 "wForm" 表单扩展。我想在我的表单中添加 "captcha"。 我已经为 "cForm" 尝试了 "myCaptcha" 组件。 http://www.yiiframework.com/wiki/733/how-to-show-a-captcha-in-cform/ 但我收到以下错误
"WForm" and its behaviors do not have a method or closure named "MyCaptcha".
如何使用 "cform captcha in wForm"?
下载扩展程序cCaptcha extension
1) 解压CaptchaExtended.zip个文件到../protected/extensions/captchaExtended/.
2) 注册 class 到 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) 在控制器中定义动作,例如网站管理员:
public function actions(){
return array(
'captcha'=>array(
'class'=>'CaptchaExtendedAction',
// if needed, modify settings
'mode'=>CaptchaExtendedAction::MODE_MATH,
),
);
}
4) 在model::rules():
中定义客户端验证public function rules(){
return array(
array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
5) 在您的视图文件中添加以下内容(在您的表单中)
$this->widget('CCaptcha'); //for captch image
echo CHtml::activeTextField($model,'verifyCode'); //text field to enter captcha text