Cross-posted from the Symfony2 Google Group since there haven't been any responses to my question.
I have the following form:
<form id="contact-form" action="{{ path('_contact') }}" method="post" {{ form_enctype(form) }}>
<fieldset>
<legend>Send us a message</legend>
{{ form_errors(form) }}
<div>
<p class="label">{{ form_label(form.name) }}</p>
{{ form_widget(form.name, { 'attr' : { 'class' : 'input' } }) }}
</div>
<div>
<p class="label">{{ form_label(form.email) }}</p>
{{ form_widget(form.email, { 'attr' : { 'class' : 'input' } }) }}
</div>
<div>
<p class="label">{{ form_label(form.subject) }}</p>
{{ form_widget(form.subject, { 'attr' : { 'class' : 'input' } }) }}
</div>
<div>
<p class="label">{{ form_label(form.message) }}</p>
{{ form_widget(form.message, { 'attr' : { 'class' : 'input', 'rows' : '8', 'placeholder' : 'Type your message here' } }) }}
</div>
<div class="hidden">
<p class="label">{{ form_label(form.honeypot) }}</p>
{{ form_widget(form.honeypot) }}
</div>
{{ form_rest(form) }}
</fieldset>
I don't like having field errors appear directly near their fields. I want to just have a list of all the errors above the form itself, which is why I don't have an error for each field. I'm using a slightly modified form_errors theme:
{# src/MajorProductions/SewingDiva/SiteBundle/Resources/views/errors.html.twig #}
{% block form_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<div class="errors">
<ul>
{% for error in errors %}
<li>{{
error.messagePluralization is null
? error.messageTemplate|trans(error.messageParameters, 'validators')
: error.messageTemplate|transchoice(error.messagePluralization, error.messageParameters, 'validators')
}}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endspaceless %}
{% endblock form_errors %}
I just put the default setup in a <div> so I can style it a bit easier.
My problem is that a list of form errors isn't displaying at all. As in, no empty <div> in the HTML, no nothing. If I put in the code for a field-level error, like say {{ form_errors(form.email) }}, it displays.
I guess I could kludge it with something like:
<div class="errors">
{{ form_errors(form.name) }}
{{ form_errors(form.email) }}
.
.
.
</div>
But that doesn't really address the problem.
Any ideas?