Search
 
SCRIPT & CODE EXAMPLE
 

PHP

symfony form get errors

private function getErrorMessages(SymfonyComponentFormForm $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;
}
Comment

symfony form errors

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
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: export mysql data to word in php 
Php :: php http method 
Php :: artisan laravel require bootstrap 
Php :: laravel vue browser cache auto clear 
Php :: wordpress create comment programmatically 
Php :: php functions parameters 
Php :: php strpos 
Php :: laravel notification attach file 
Php :: laravel module package 
Php :: ci4 throw new exception 
Php :: logout from all the devices in the jwt api laravel 
Php :: laravel select where with total sum query to get all data with sum 
Php :: html in php function 
Php :: generate fake name php 
Php :: php shortcode wordpress return content with shortcodes 
Php :: display pdf file in laravel 
Php :: is null php 
Php :: laravel wrong timestamp 
Php :: acf wordpress loop through and display blog posts order by date and type 
Php :: laravel copy 
Php :: php preg_quote 
Php :: laravel array in lang 
Php :: php warning: php startup: unable to load dynamic library 
Php :: Laravel - Send mail using mail class 
Php :: Predefined Constants php 
Php :: number data type in laravel migration 
Php :: Artisan namespace 
Php :: flatten in array php 
Php :: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes 
Php :: custom pagination in laravel 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =