简体   繁体   中英

Symfony2 FOSUserBundle => Customize error

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 %}

2.(!) The message is hardcoded in the validation, it seems. Located in: Vendor/bundles/FOS/UserBundle/Validator/Password.php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM