我在我的一个表格中使用过capcha。它总是给验证码错误。
以下是我的代码:
SchoolsController.php
public function actions() {
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fontFile' => '@yii/captcha/SpicyRice.ttf',
'padding' => '0',
]
];
}
型号:
['verifyCode', 'captcha', 'captchaAction' => 'schools/captcha'],
查看:
echo $form->field($modelSchoolRequestEarlyAccess, 'verifyCode')->widget(Captcha::className(), [
'options' => [
'placeholder' => 'Enter characters in the image',
'autocomplete' => 'off',
'maxlength' => 20
],
'captchaAction' => 'schools/captcha',
'template' => "<div class='field'><span><strong>*</strong>".Yii::t('frontend/quicksignup','VerifyCodeLabel').":</span></span>\n<div>{image}{input}<i class='refresh-code-icn' id='get-new-code'></i></div></div>"
])->label(false);
我已在模型和视图中将验证码操作指定为schools/captcha
。但它总是显示验证不正确。
我做错了什么?
答案 0 :(得分:0)
您是否添加了规则?
public function rules()
{
$rules = parent::rules();
$rules[] = ['captcha', 'required'];
$rules[] = ['captcha', 'captcha'];
return $rules;
}
答案 1 :(得分:0)
你写了SchoolController.php,你的路线是学校 s 。所以你可能需要调整你的路线到学校/验证码