use Symfony\Component\Form\FormError; // Create a new form object $form = $this->createForm(MyFormType::class); // Handle form submission $form->handleRequest($request); // Check if the form is valid if ($form->isValid()) { // Do something } else { // Get all errors $errors = $form->getErrors(true, false); // Display errors foreach ($errors as $error) { echo $error->getMessage(); } }
use Symfony\Component\Form\FormError; // Create a new form object $form = $this->createForm(MyFormType::class); // Handle form submission $form->handleRequest($request); // Check if the form is valid if ($form->isValid()) { // Do something } else { // Get errors for the "email" field $errors = $form->get('email')->getErrors(true, false); // Display errors foreach ($errors as $error) { echo $error->getMessage(); } }In this example, we create a new form object using the MyFormType class. We handle the form submission and check if the form is valid. If the form is not valid, we use the getErrors method to retrieve all errors for the "email" field. We then loop through the errors and display their messages. Package library: Symfony Form Component