Maison > Article > développement back-end > yii20验证码不能随网页一起刷新/出现site/captcha的错误
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>
另外出现
解决方法:
在 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教程有兴趣的朋友有所帮助。