View Single Post
  #4 (permalink)  
Old 06-24-2008, 09:13 PM
jweber jweber is offline
Senior Member
 
Join Date: Jun 2008
Location: Florida
Posts: 108
Default

Every form I've created so far has a method that creates the form and returns the form object. Then within the action method itself (where the form action points) I handle getting that form object, sending the user submitted POST values to the form object, displaying messages to the user, etc...

For example:
Code:
    public function indexAction()
    {
        // get the needed namespaces
        $viewNamespace = new Zend_Session_Namespace('view');

        // get the form and save to a view var
        $this->view->form = $this->getEmailSenderForm();

        // check if the form was submitted via post
        if ($this->_request->isPost()) {
            if ($this->view->form->isValid($this->_request->getPost())) {
                // get the sanitized values from the form object
                $sanitizedValues = $this->view->form->getValues();

                // since the form was submitted send the post values to the form
                // object to persist their values
                $this->view->form->populate($sanitizedValues);
                
                // the form is valid, save to db or whatever else you need to do
            } else {
                // the form is not valid, send the user back to the form with a message
            }
        }
    }

Last edited by jweber : 06-25-2008 at 01:32 PM.
Reply With Quote