I (stupidly) didn't check if the form passed to the helper after a form submit was the form that was posted. This meant that if the posted form wasn't the first form that was posted, the values passed along with the first form were the values stored in the session.
if ($postId)
should have been if ($postId === $formId)
public function direct($form, $persistData = false, $redirectUrl = null)
{
$formId = $form->getElement('unique_form_id')->getValue();
$currentUrl = implode (
'/',
array (
$this->getRequest()->getModuleName(),
$this->getRequest()->getControllerName(),
$this->getRequest()->getActionName()
)
);
$session = new Zend_Session_Namespace('prg');
$redirectUrl = $redirectUrl ? $redirectUrl : $currentUrl;
if ($this->getRequest()->isPost())
{
$postId = $this->getRequest()->getPost('unique_form_id');
if ($postId === $formId)
{
$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
$postUrl = $currentUrl;
$session->$postUrl->$postId = array (
'url' => (string) $redirectUrl,
'id' => (string) $postId,
'post' => (array) $this->getRequest()->getPost(),
'persist' => (bool) $persistData
);
Zend_Session::writeClose(true);
$response = $redirector ->setCode(303)
->setExit(true)
->gotoUrl($redirectUrl);
return $response;
}
else {
return false;
}
}
else {
$urlSessionData = $session->$currentUrl;
// Results shown below
Zend_Debug::dump($urlSessionData);
if ($urlSessionData->$formId != null)
{
$formSessionData = $urlSessionData->$formId;
$formPersist = $formSessionData['persist'];
$formPostData = $formSessionData['post'];
if (!$formPersist)
{
unset($urlSessionData->$formId);
}
if(!empty($formPostData))
{
$form->isValid($formPostData);
}
return $formPostData;
}
else {
return false;
}
}
}