1
votes

In Zend Framework, while I'm in the controller is it possible to retrieve the error messages if form->isValid() returns false? I add form elements with a custom error message and I do not want to display the error message beneath the input field but on the top of the form.

Regards Andrea

1

1 Answers

1
votes

Yes. You can get error messages when isValid() fails using getMessages() method:

 if ($this->getRequest()->isPost()) {                       
     if ($yourForm->isValid($_POST)) {
        // success       
     } else {
        // isValid fails

        $errorMsgs = $yourForm->getMessages());    

        // process them, assign them to a view variable
        // and display in a view.
        // you can also create a view helper or a partial view script
        // that would handle the display of the messages.
     }
 }

You may also remove 'Errors' decorator from your elements if you don't want to have errors shown below them.