In complement to @VAShhh response. With some more details: You need to do two things, populate your form fields with the POSTed data and applying security filters and validators to that data. Zend_Form provides one simple function which perform both, it's isValid($data).
So you should:
- build your form
- test you are in a POST request
- populate & filter & validate this data
- either handle the fact in can be invalid and re-show the form wich is now decorated with Errors OR retrieve valid data from the form
So you should get:
function submitformAction() { $form = new Form_MyForm(); $request = $this->getRequest(); if ( $request->isPost() ) { if (!$form->isValid($request->getPost())) { $this->view->form = $form; // here maybe you could connect to the same view script as your first action // another solution is to use only one action for showform & submitform actions // and detect the fact it's not a post to do the showform part } else { // values are secure if filters are on each form element // and they are valid if all validators are set $securizedvalues = $form->getValues(); // temporary debug print_r($securizedvalues);die(); // here the nice thing to do at the end, after the job is quite // certainly a REDIRECT with a code 303 (Redirect after POSt) $redirector = $this->_helper->getHelper('Redirector'); $redirector->setCode(303) ->setExit(true) ->setGotoSimple('newaction','acontroller','amodule'); $redirector->redirectAndExit(); } else { throw new Zend_Exception('Invalid Method'); } }
And as said in the code re-showing the form you shoudl really try to use the same function for both showing and handling POST as a lot of steps are really the same:
- building the form
- showing it in the view in case of errors
By detecting the request is a POST you can detect you are in the POST handling case.