【问题标题】:Capcha always show incorrect验证码总是显示不正确
【发布时间】:2020-01-15 01:36:50
【问题描述】:

我在其中一种形式中使用了验证码。总是报验证码不正确的错误。

下面是我的代码:

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。但总是显示验证不正确。

我做错了什么??

【问题讨论】:

    标签: yii2 captcha


    【解决方案1】:

    您编写了 SchoolController.php,您的路线是到学校s。所以你可能需要调整去学校/验证码的路线

    【讨论】:

    • 我已经更正了。这是错字。我的控制器名称是 SchoolsController
    【解决方案2】:

    你添加规则了吗?

       public function rules()
    {
        $rules = parent::rules();
        $rules[] = ['captcha', 'required'];
        $rules[] = ['captcha', 'captcha'];
        return $rules;
    }
    

    【讨论】:

    • 是的,我做到了。在我的问题中,您可以看到我添加了验证码规则。但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多