开发者

POSTing to different action with Zend_Form (and validation)

I'm using Zend Framework, and am curious about how people handle form submission. Right now, I'm using something like this:

 public function editAction()
 {
    $form = my_form();
    $this->view->form = $form;

    if ($this->getRequest()->isPost() {
       $params = $this->getRequest()->getPost();

       if (开发者_如何学Python$form->isValid($params) {
          // process form
       }

    }
  }

Having the page try to repost the form on refresh is just annoying, and frustrating for the user. I'd like to have all the form processing moved out of the 'edit' action, and into an 'update' action (a more RESTful approach). However, I haven't figured out a good way to take advantage of Zend_Form's built in validation decorators without using the above approach. Using the method above, error messages appear automatically if I $form->populate() a form after calling $form->isValid().

Is there any good way to persist validation messages on a form across requests (using the decorators). If not, does anyone have a solid solution for storing form validation in the session?

Thanks.


After processing the form forward to another controller/action. This will send a redirect header to the client and he will be able to refresh the page without the annoying alert window.

if ($form->isValid($params) {
    // process form
    ....
    ....
    $this->_helper->Redirector->goto('another-action');
}


My way is sth like this:

/index action -> list of lets say blog posts ->update action -> updating a blog post selected in index in update action (pseudocode):

if(is_post){
  if(data_valid){
    update_data()
    redirect_to_index()
  } else {
    show_messages()
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜