Yes, I'm using the MVC component.

The redirections are managed by the dispatcher, actually, when i've talked
about forms redirection i was talking about the redirector helper or the
_redirect method.

With your example, you are allowing to do re-submit. If someone fills the
form and submit, he'll see the same page again because the 'enquiryAction'
is responsible of two things: show the form and validate the form. If the
form validation goes wrong, the user can hit the reload button (CTRL+R in
firefox) and can see the nasty popup window alerting about double submit.
This is one thing i don't want to show, ever.

The optional flow i suggest:

public function init()
{
    $this->form = new Zend_Form;
    $this->form->setId('form-survey-general');
    (...) validators, decorators, ....
}

public function showFormAction()
{
      $this->view->form = $this->form;
}

public function processFormAction()
{
    if($this->form->isValid()) {
       $this->_redirect('/thankyou');
    } else {
       $this->_redirect('/showForm');
    }
}

public function thankyouAction()
{
     // you can hit reload as many times you want, this is a GET request.
The browser did not record the processForm set in browser's history, so you
can go back without nasty popups.
}

Obviously, the form component knows which is his related data thanks to the
ID, so the process gets clean and the navigation gets even more clean. I
know saving data in session is not the best practice, but it's the only way
i know to prevent re-submits and to make easier the forms management.

On Jan 29, 2008 10:54 AM, Simon Mundy <[EMAIL PROTECTED]> wrote:

> Hi Xavier
>
> Are you also using the MVC component? I highly recommend you leave the
> redirection of actions to the dispatcher and the form to do the
> processing. I'm not a huge fan of creating sessions for form data
> unless they really do need to be session-aware (like multi-page forms,
> etc). You can get around the double-submission simply by utilising
> HTTP requests.
>
> public function enquiryAction()
> {
>     $form = new My_Enquiry_Form();
>     // do stuff...
>
>     $request = $this->getRequest();
>
>     if ($request->isPost() && $form->isValid($request->getPost()) {
>         // do stuff with form values...
>         $this->_helper->redirector('thankyou');
>     }
>
>     $this->view->form = $form;
> }
>
> public function thankyouAction()
> {
>     // Write out thankyou script
> }
>
> No javascript required :)
>
> > Great work with ZF 1.5 !!
> >
> > By the way, i've started to experiment with Zend_Form and I find it
> > more intuitive than his counterpart (Pear Quickform) to me. But one
> > thing i would like to have in a near future, is the ability to
> > implement the Post-Redirect-Get pattern with Zend_Form.
> >
> > Now, with Zend_Form you can POST to the same action or to another
> > one, but the problem arises when someone hits the "reload" button in
> > his browser, showing the nasty "Caution: you are about to send a
> > form again...bla bla..." message.
> >
> > May be could be a good idea to implement a Session container and
> > save the form data into, using a special ID for each form. So, if
> > the action processing the form sees is not valid can make a
> > 'redirect' and the Form Component can redraw the form with session
> > data, validation errors, etc....
> >
> > Yes, i know it's not a major issue, but i hate the 'double submit'
> > message. Now i'm working with Ajax and encrypted tokens to avoid
> > double submits (accidental or not), but i don't want to rely always
> > on javascript.
>
>
> --
>
> Simon Mundy | Director | PEPTOLAB
>
> """ " "" """""" "" "" """"""" " "" """"" " """"" "  """""" "" "
>
> 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
> Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
> 4124
> http://www.peptolab.com
>
>


-- 
Xavier Vidal Piera
Enginyer Tècnic Informàtic de Gestió
Tècnic Especialista Informàtic d'equips
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://web.xaviervidal.net
610.68.41.78

Reply via email to