views:

298

answers:

1

I'm tring to customize error rendering in my form according to this example.

Here is my code:

if ($this['message']->hasError()) {
  $error_msg = '<ul>';
  foreach ($this['message']->getError() as $error) $error_msg .= "<li>$error</li>";
  $error_msg .= '</ul>';
}

return $error_msg;

but when $this['message'] has error this code returns '<ul></ul>' so it seems foreach ($this['message']->getError() as $error) causes no iterations

$this['message']->getError() returns sfValidatorError object - maybe something changed in symfony 1.4 and it isn't iterable anymore...

At first I thought that all magic in that example happened because of object being placed in $error by iteration implements __toString() but it seems no iterations happens at all...

A: 

you should have variable $form which holds the Form that you're displaying, and the code should be $form['message']->hasError() and $form['message']->getError() , where 'message' is a widget in your form. Do not use $this, as it doesn't hold the form in this context.

Zoja
I use this code inside one of my form's method, so `$this` correctly references to my form. After all `$form['message']->hasError()` returns `true` so it is in a proper context.
HongKilDong
can you paste exactly your action and view connected with this form ? and the form itself ? I want to see if you have maybe errors in the flow concept
Zoja