public function getErrorMessages(Form $form)
    {
        $errors = '';

        foreach ($form->getErrors() as $key => $error) {
            $errors .= $error->getMessage().', ';
        }

        /** @var Form $child */
        foreach ($form->all() as $child) {
            if (!$child->isValid()) {
                $fieldName = $child->getConfig()->getOption('label', null);

                if (empty($fieldName)) {
                    $fieldName = $child->getName();
                }

                $errors .= sprintf("[%s] %s, ", $fieldName, $this->getErrorMessages($child));
            }
        }

        return rtrim($errors, ', ');
    }
public function getErrorMessages(Form $form)
    {
        $errors = '';

        foreach ($form->getErrors() as $key => $error) {
            $errors .= $error->getMessage().', ';
        }

        /** @var Form $child */
        foreach ($form->all() as $child) {
            if (!$child->isValid()) {
                $fieldName = $child->getConfig()->getOption('label', null);

                if (empty($fieldName)) {
                    $fieldName = $child->getName();
                }

                $errors .= sprintf("[%s] %s, ", $fieldName, $this->getErrorMessages($child));
            }
        }

        return rtrim($errors, ', ');
    }
public function getErrorMessages ( Form $ form ) { $ errors = '' ; foreach ( $ form -> getErrors ( ) as $ key => $ error ) { $ errors .= $ error -> getMessage ( ) . ', ' ; } /** @var Form $child */ foreach ( $ form -> all ( ) as $ child ) { if ( ! $ child -> isValid ( ) ) { $ fieldName = $ child -> getConfig ( ) -> getOption ( 'label' , null ) ; if ( empty ( $ fieldName ) ) { $ fieldName = $ child -> getName ( ) ; } $ errors .= sprintf ( "[%s] %s, " , $ fieldName , $ this -> getErrorMessages ( $ child ) ) ; } } return rtrim ( $ errors , ', ' ) ; }
Get all errors that occurred in a form

@param  \Symfony\Component\Form\Form $form
@return string                       the error string
Get all errors that occurred in a form