约束验证不会在表单中显示消息

时间:2013-12-30 03:20:52

标签: symfony constraints message

我有一个包含具有$email属性的用户实体的表单:

{{ form_start(form, {'attr': {'class':'form-horizontal'} }) }}
{{ form_errors(form) }}
...
    <div class="control-group formSep">
        <label class="control-label">
            {{ form_label(form.email, 'E-mail:') }}
        </label>
        <div class="controls text_line">
             {{ form_widget(form.email) }} 
        </div>
    </div>
...
{{ form_rest(form) }}
{{ form_end(form) }}

用户实体对$email

有约束
/**
 * @ORM\Column(type="string", length=64)
 * @Assert\Email
 * @Assert\NotBlank
 */
 protected $email;

当我输入无效的电子邮件值时,实体不会在数据库中保留(好),但twig也不会显示错误(错误)。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

就像在文档中说的form_errors(form)渲染全局错误(如类约束错误等...),显示电子邮件字段的错误,你应该使用form_errors(form.email)。

http://symfony.com/doc/current/reference/forms/twig_reference.html#form-errors-view