Thursday, March 14, 2013

Symfony2: How to find out the form errors

How to find out the form errors in Symfony2. Just add that code to your Controller:
if ($form->isValid()) {
...

} else {
    foreach($form->getChildren() as $child) {
        foreach( $child->getErrors() as $error) {
            print($error->getMessageTemplate()); 
        }
    }
}
It takes into consideration only the errors of the form fields. If you want to check errors of the form too, add that:
foreach ($form->getErrors() as $error) {
    print($error->getMessageTemplate());
}

Wednesday, March 13, 2013

I am a cool php programmer :)