As Symfony2 Form component with tight integration with the validation component is extremely powerful, I have hard times understanding how I can get the list of validation errors at PHP side with proper reference to the invalid field. By "reference", I mean some hint that I can further get the field and it's ID (like with $form->get($failedChild)->vars['id']
or something).
$form->getErrors()
returns the list of the errors, but this array of FormErrors does not include any reference to the field that is invalid.
I found a Gist that shows something like that, but at least on 2.3 or 2.4 all errors are still bound to the main form.
error_bubbling
option does not change the behavior as I first thought it would.
Update #1
In the end, I'd like to receive a JSON representation of all form errors and return it back to the client. A sample JSON would be something like
{
"invalid_field_id": "This field has invalid value"
}
The ID of the field can be received over $field->vars['id']
but it seems that all validation errors are returned in $form->getErrors()
instead of $field->getErrors()