$form = new Zend_Form(); //form elements and validators added here if ($form->isValid($_POST)) { //process form data } else { $errors = $form->getMessages(); foreach($errors as $fieldName => $fieldErrors) { echo "Error(s) found in " . $fieldName . ": "; foreach($fieldErrors as $errorMessage) { echo $errorMessage . "
"; } } }
public function someAction() { $form = new Application_Form_SomeForm(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { //process form data } else { $this->view->errors = $form->getMessages(); } } $this->view->form = $form; }In this code example, a Zend_Form object is created by an application-specific form class, Application_Form_SomeForm. If the form data is submitted via POST request and is invalid, the getMessages method is called to retrieve the errors. The errors are then assigned to a view variable and sent to the view for display. Overall, Zend_Form provides a simple and effective way to build and validate HTML forms in PHP. It is a part of the Zend Framework, a package library for PHP programming language.