I have a registration form - from FOSUserBundle this is in the template:
{% form_theme form 'AcmeMyBundle:Form:errors.html.twig' %}
<form class="big-spacer" action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
<input class="btn little-spacer" type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>
</form>
Here is errors.html.twig
:
{% block field_errors %}
{% spaceless %}
{% if errors|length > 0 %}
<ul class="little-spacer nav text-error">
{% for error in errors %}
<li>{{loop.index}}. {{ error.messageTemplate|trans(error.messageParameters, 'validators') }}</li>
{% endfor %}
</ul>
{% endif %}
{% endspaceless %}
{% endblock field_errors %}
I have just added some css classes from TwitterBootstrap.
The problem is that I get some of the messages for the validation twice.
My form has 4 fields - Username, Email, Password, Confirm Password
I tried to break as many validation rules I can and here is the output:
For Username
:
- This username is already used. Please choose another one.
- The username is too short - please enter at least 2 symbols.
- The username is too short - please enter at least 2 symbols.
For email
:
- Please enter a valid email.
- Please enter a valid email.
and if I enter already used email, the error is shown only once:
- This email is already used.
And for the passwords
:
If they are short:
- The password is too short - please enter at least 6 symbols.
- The password is too short - please enter at least 6 symbols.
And if they don't match:
- The entered passwords don't match.
Another strange thing is that when I resubmit the form, but it's still not valid, the notice for the length of the password is only one:
- The password is too short - please enter at least 6 symbols.
and before resubmitting, they were two.
Do you have any ideas why some of the errors are displayed twice and how to fix this? Thank you very much in advance! :)
UPDATE
This is C:\xampp\htdocs\Project\src\Acme\MyBundle\Entity\User.php
namespace Acme\MyBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
And in C:\xampp\htdocs\Project\app\Resources\FOSUserBundle\translations\
I copied the file validators.en.yml
and in it and removed the [-Inf, Inf]
part and changed the messages a bit.
I also overrode the validation file - I copied it here:
C:\xampp\htdocs\Project\src\Acme\MyBundle\Resources\config\validation.xml
I changed only the minimum length of the password. Everything else is the same as in the original file.
My bundle extends FOSUserBundle:
C:\xampp\htdocs\Project\src\Acme\MyBundle\AcmeMyBundle.php
this file contains the following:
<?php
namespace Acme\BudgetTrackerBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeBudgetTrackerBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}