Adding custom form field errors within controllers in Symfony

Every field in Symfony now is an instance of a form object.  To add custom errors in the controller upon form submission, you have to access the form object of the field then add the custom error to it.

$error = new formerror("Your field custom error message here.");
$form->get('fieldName')->addError($error);

//You will need to include the formerror class at the top of the file:

use Symfony\Component\Form\FormError

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

Your email address will not be published. Required fields are marked *