“Symfony Formo obtenga errores” Código de respuesta

Symfony Formo obtenga errores

private function getErrorMessages(\Symfony\Component\Form\Form $form) {
    $errors = array();
    foreach ($form->getErrors() as $key => $error) {
        $template = $error->getMessageTemplate();
        $parameters = $error->getMessageParameters();

        foreach($parameters as $var => $value){
            $template = str_replace($var, $value, $template);
        }

        $errors[$key] = $template;
    }
    if ($form->hasChildren()) {
        foreach ($form->getChildren() as $child) {
            if (!$child->isValid()) {
                $errors[$child->getName()] = $this->getErrorMessages($child);
            }
        }
    }
    return $errors;
}
Sleepy Squirrel

Symfony Form Errores

if( $form->isValid() )
{
    // ...
}
else
{
    // get a ConstraintViolationList
    $errors = $this->get('validator')->validate( $user );

    $result = '';

    // iterate on it
    foreach( $errors as $error )
    {
        // Do stuff with:
        //   $error->getPropertyPath() : the field that caused the error
        //   $error->getMessage() : the error message
    }
}
SECRET MYSTERY

Respuestas similares a “Symfony Formo obtenga errores”

Preguntas similares a “Symfony Formo obtenga errores”

Más respuestas relacionadas con “Symfony Formo obtenga errores” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código