Colin Guthrie schreef:
Hi,
Apologies if this has been covered before, but I did search quite a bit
and asked on IRC before posting!
As per general recommendations, in my code, I never produce any output
on a posted page, but instead issue a redirect header. This prevents the
back button breaking and people accidentally double posting things when
doing so etc. Great.
I usually only redirect if a post has been successful, otherwise I
redisplay the form.
Something like:
someAction()
{
$request = $request = $this->getRequest();
$myForm = new My_Form();
if( $request->isPost() )
{
$formData = $request->getPost();
if( $myForm->isValid( $formData ) )
{
/*
* do something with the $formData and if successful redirect
*/
if( $processingOfFormDataSuccessful )
{
return $this->_redirector->gotoRoute( array(
'module' => 'myModule',
'controller' => 'myController',
'action' => 'myAction'
),
'default',
true
);
}
}
}
// not redirected, so (re)display the form in the view
$this->view->myForm = $myForm;
}
HTH