My check looks like
Acme\UserBundle\Entity\User: constraints: - \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields:username, message: "Username already in use" } - \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields:email, message: "Email address already in use" } properties: username: - NotBlank: ~ - MinLength: { limit: 2, message: "Your username must have at least {{ limit }} characters." } email: - Email: message: The email "{{ value }}" is not a valid email. checkMX: true
My controller is like:
$form = $this->createForm(new RegistrationType()); $form->bindRequest($request); if ($form->isValid()) {
I am trying to create a user registration controller that is sent through an ajax request. However, when errors in the check are triggered, the $error variable looks like this:
[2011-11-07 19:19:44] app.INFO: array ( 0 => Symfony\Component\Form\FormError::__set_state(array( 'messageTemplate' => 'Email address already in use', 'messageParameters' => array ( ), )), 1 => Symfony\Component\Form\FormError::__set_state(array( 'messageTemplate' => 'Your username must have at least {{ limit }} characters.', 'messageParameters' => array ( '{{ value }}' => '1', '{{ limit }}' => 2, ), )), ) [] []
The problem is that I do not know in which field this error corresponds. Is there any way to find this data so that when sending a json response I can associate the error message with the corresponding field.
ed209
source share