首頁 > 後端開發 > php教程 > yii20驗證碼不能隨網頁一起刷新/出現site/captcha的錯誤

yii20驗證碼不能隨網頁一起刷新/出現site/captcha的錯誤

WBOY
發布: 2016-07-28 08:25:51
原創
1277 人瀏覽過

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></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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板