1
votes

I'm developping a website using Symfony2 and FOSUserBundle for the user side. I'm trying to customize the registration form, and i'm experimenting some problems.

  1. I tried to follow the doc to include field errors beside the field, but it only show it on the top of the form;
  2. When both passwords aren't the same, there's an error written in the top of the form: The value is not valid. This is not very clear, and I'd like to translate it in french but I can't seem to find it in the language files. I used to translate all the forms, except that error.

Here is my fields template:

{% block field_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<ul class="list_error">
{% for error in errors %}
<li>{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock field_errors %}


{% block field_row %}
{% spaceless %}
<tr>
    <td>
        <label for="{{ form.vars.id }}">{{ form.vars.id|trans( {}, "FOSUserBundle" ) }}</label>
    </td>
    <td>
        {{ form_widget(form) }}
        {{ form_errors(form) }}
    </td>
</tr>
{% endspaceless %}
{% endblock field_row %}
1

1 Answers

1
votes

The "invalid" error is a bit special in that it is the same by default for all fields. You can override it in the options of your repeated field (or any field, for that matter):

$builder->add('password', 'repeated', array(
    'type' => 'password',
    'invalid_message' => 'Please enter the same password twice',
));

Btw, the bubbling of the error to the root form for repeated fields was an issue that has been fixed in Symfony 2.1.