I\'m trying to get a clean error message after validating my Subscribe Entity :
/**
* Subscribe
* @UniqueEntity(\"email\")
* @ORM\\Table(name=\"subscr
try this:
$validator = $this->get('validator');
$errors = $validator->validate($email);
if (count($errors) >0) {
$messages = [];
foreach ($errors as $violation) {
$messages[$violation->getPropertyPath()][] = $violation->getMessage();
}
return new JsonResponse($messages);
}
In this way I have create an array of errors, where the key is the not valid field, you can change this logic and add only the name of the field in front of the error and return a simple string.
This code can works with all fields in the form