code: private function getErrors(Form $form)
      {
          $errors = array();
  
          if ($form->isSubmitted() && $form->isValid()) {
              return $errors;
          }
  
          $id = $form->createView()->vars['id'];
  
          foreach ($form->getErrors() as $error) {
  
              if (!isset($errors[$id])) {
                  $errors[$id] = array();
              }
  
              $errors[$id][] = $error->getMessage();
          }
  
          foreach ($form->all() as $child) {
              $errors = array_merge($this->getErrors($child), $errors);
          }
  
          return $errors;
      }
docs: Gets error message recursively through a form and all its children
  
  @param \Symfony\Component\Form\Form $form
  
  @return array