symfony3 Validation


In fact, form validation is based from a component, named "Validator Component".

You can often use the dedicated service if you did't have to show a form in a template. Like APIs. You may validate datas in the same way, like this :

For example, based on symfony doc :

$validator = $this->get('validator');
$errors = $validator->validate($author);

if (count($errors) > 0) {
     * Uses a __toString method on the $errors variable which is a
     * ConstraintViolationList object. This gives us a nice string
     * for debugging.
    $errorsString = (string) $errors;