开发者

Why aren't my errors appearing on a Symfony2 form?

I have the following change password form which overrides the form from FOSUserBundle. If I enter a non-matching password/repeated password, the form displays again without any errors and doesn't redirect

<div id="change_password_wrapper">
  <h2>Change your password</h2>
  <form action="{{ path('fos_user_change_password') }}" {{ form_enctype(form) }} method="POST" class="fos_user_change_password">
    {%if form_errors(form)%}
    <div class="ui-state-error ui-corner-all">
      <p>
        <span class="ui-icon ui-icon-alert" style="float: left; margin-rig开发者_高级运维ht: .3em;"></span>
<strong>Error:</strong>
      {{ form_errors(form) }}
        </p>
    </div>
    {% endif %}
        <div class="form-row">
          {{ form_label(form.current, 'Current password: ') }}
          {{ form_errors(form.current) }}
          {{ form_widget(form.current) }}
        </div>
        <div class="form-row">
          {{ form_label(form.new.first, 'New password: ') }}
          {{ form_errors(form.new.first) }}
          {{ form_widget(form.new.first) }}
        </div>
        <div class="form-row">
          {{ form_label(form.new.second, 'Verify password: ') }}
          {{ form_errors(form.new.second) }}
          {{ form_widget(form.new.second) }}
        </div>
      <div class="form_row">
          <input type="submit" value="{{ 'change_password.submit'|trans({}, 'FOSUserBundle') }}" />
      </div>
    {{ form_rest(form) }}
  </form>
</div>


You should also add this to your form:

{{ form_errors(form.new) }}

Now you should have an error message

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜