【问题标题】:Bad Code Value on chrome with gregwar captcha带有gregwar验证码的chrome上的错误代码值
【发布时间】:2014-10-07 18:55:27
【问题描述】:

我在让 gregwar 验证码在 Chrome 上工作时遇到了一些麻烦。 我有一个 symphony 2.3 上的网络应用程序并使用 gregwar 验证码(“dev-master”)。

我在表单上添加了验证码。 它在 IE 和 Firefox 上运行良好。 但是对于 Chrome,在表单验证之后,我总是会收到“错误的代码值”错误。 事实上,当我在compare函数上查看Gregwar\CaptchaBundle\Validator\CaptchaValidator.php 时,我确实有一个与code 不同的$expectedCode

任何想法为什么它可以在 firefox 和 IE 上运行,但不能在 Chrome 上运行?

您可以在这里测试页面:http://www.nokachi-lyon.fr/contacts

有关信息,这是我的 Gregwar Captcha 实现:

config.yml 我有:

gregwar_captcha:
  width: 150
  height: 35
  length: 5
  distortion: false
  invalid_message: "My error message"

Form 我有:

public function buildForm(FormBuilderInterface $builder, array $options){
  $builder->add('myField','text')
          ->add('captcha', 'captcha');
}

FormView 我有:

{% form_theme form with ['::captcha.html.twig','::formError.html.twig'] %}
<form action="{{ path('club_contacts') }}" method="post" {{ form_enctype(form) }}>
    ...
    {{ form_widget(form.captcha) }}
    ...
</form>

captcha.html.twig我有:

{% block captcha_widget %}
 <p>My Message :
    {{ form_widget(form) }}
    <img src="{{ captcha_code }}" title="captcha" width="{{ captcha_width }}" height="{{ captcha_height }}" />
  </p>
{% endblock %}

【问题讨论】:

    标签: google-chrome symfony captcha symfony-2.3


    【解决方案1】:

    我最终设法使它工作! 我不确定为什么它现在可以工作,但这是解决方法。

    Controler,我曾经有过这样的事情:

    public function contactsAction(Request $request){
        [...]
        if ($request->isMethod('POST')) {
            $form->bind($request);
            [...]
        }
        return $this->render([...]);
    } 
    

    我把它改成以下:

    public function contactsAction(Request $request){
        [...]
        $form->bind($request);
        if ($request->isMethod('POST')) {
            [...]
        }
        return $this->render([...]);
    } 
    

    现在它工作得很好。

    【讨论】:

    • 嗨,我有一个类似的问题,我正在使用$form = $this-&gt;createForm(new MyFormType()); $form-&gt;handleRequest($request); if ($form-&gt;isValid()) { /* something */ },我也有同样的行为。所以基本上我正在使用handleRequest,这有点像bind,但仍然不起作用。
    • 抱歉,我发现了自己的问题——我有两个单独的表格,每个表格都有一个验证码。验证码值在会话中被覆盖。
    猜你喜欢
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 2017-09-26
    相关资源
    最近更新 更多