首页 > 后端开发 > php教程 > yii20验证码不能随网页一起刷新/出现site/captcha的错误

yii20验证码不能随网页一起刷新/出现site/captcha的错误

WBOY
发布: 2016-07-28 08:25:51
原创
1278 人浏览过

1.不能随网页刷新而刷新的错误解决办法:
修改源代码 vendor/yiisoft/yii2/captcha/CaptchaValidator.php

<code><span>/**
     *<span> @inheritdoc</span>
     */</span><span>public</span><span><span>function</span><span>clientValidateAttribute</span><span>(<span>$object</span>, <span>$attribute</span>, <span>$view</span>)</span>
    {</span><span>$captcha</span> = <span>$this</span>->createCaptchaAction();
        <span>$code</span> = <span>$captcha</span>->getVerifyCode(<span>true</span>);
        <span>$hash</span> = <span>$captcha</span>->generateValidationHash(<span>$this</span>->caseSensitive ? <span>$code</span> : strtolower(<span>$code</span>));
        <span>$options</span> = [
            <span>'hash'</span> => <span>$hash</span>,
            <span>'hashKey'</span> => <span>'yiiCaptcha/'</span> . <span>$captcha</span>->getUniqueId(),
            <span>'caseSensitive'</span> => <span>$this</span>->caseSensitive,
            <span>'message'</span> => Yii::<span>$app</span>->getI18n()->format(<span>$this</span>->message, [
                <span>'attribute'</span> => <span>$object</span>->getAttributeLabel(<span>$attribute</span>),
            ], Yii::<span>$app</span>->language),
        ];
        <span>if</span> (<span>$this</span>->skipOnEmpty) {
            <span>$options</span>[<span>'skipOnEmpty'</span>] = <span>1</span>;
        }

        ValidationAsset::register(<span>$view</span>);

        <span>return</span><span>'yii.validation.captcha(value, messages, '</span> . json_encode(<span>$options</span>, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . <span>');'</span>;
    }
}</code>
登录后复制
<code><span>$code</span><span>=</span><span>$captcha</span><span>-></span>getVerifyCode(<span>false</span>); <span>false</span>改成<span>true</span></code>
登录后复制

另外出现
 yii20验证码不能随网页一起刷新/出现site/captcha的错误
解决方法:
在 model中修改captchaAction的值

<code>    [<span>'verifyCode'</span>, <span>'captcha'</span>,<span>'message'</span> =><span>'验证码错误'</span>,<span>'captchaAction'</span>=><span>'login/captcha'</span>],</code>
登录后复制

在view中:

<code><span><span></span>= <span>$form</span>->field(<span>$loginForm</span>, <span>'verifyCode'</span>,[<span>'options'</span>=>[<span>'class'</span> => <span>'form-group'</span>]])->widget(Captcha::className(),[
                <span>'captchaAction'</span> => <span>'/login/captcha'</span>,
                <span>'imageOptions'</span> => [<span>'alt'</span>=><span>'点击换图'</span>,<span>'title'</span>=><span>'点击换图'</span>,<span>'style'</span>=><span>'cursor:pointer'</span>],
                <span>'options'</span> => [
                    <span>'placeholder'</span> => <span>'验证码'</span>,
                    <span>'class'</span> => <span>'form-control'</span>,
                    <span>'style'</span> => <span>'margin-top:10px;'</span>
                ]
            ])->label(<span>false</span>); <span>?></span></span></code>
登录后复制
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了 yii20验证码不能随网页一起刷新/出现site/captcha的错误,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板