Home > Backend Development > PHP Tutorial > The yii20 verification code cannot be refreshed along with the web page/site/captcha errors occur.

The yii20 verification code cannot be refreshed along with the web page/site/captcha errors occur.

WBOY
Release: 2016-07-28 08:25:51
Original
1278 people have browsed it

1. Solution to the error that cannot be refreshed when the web page is refreshed:
Modify the source code 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>
Copy after login
<code><span>$code</span><span>=</span><span>$captcha</span><span>-></span>getVerifyCode(<span>false</span>); <span>false</span>改成<span>true</span></code>
Copy after login

Another appearance
 yii20验证码不能随网页一起刷新/出现site/captcha的错误
Solution:
Modify the value of captchaAction in the model

<code>    [<span>'verifyCode'</span>, <span>'captcha'</span>,<span>'message'</span> =><span>'验证码错误'</span>,<span>'captchaAction'</span>=><span>'login/captcha'</span>],</code>
Copy after login

In the 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>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the yii20 verification code cannot be refreshed with the web page/site/captcha errors occur, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template