我设法获得了 Zend Mutipage 表单教程http://framework.zend.com/manual/en/zend.form.advanced.html代码中显示的示例,但是我遇到了验证问题。
表单的第一部分加载正常,但是当我单击“保存并继续”按钮到表单的第二部分时,它包含验证错误消息。(这是不正确的,因为只有在用户提交子表单的第二部分时才会弹出验证错误)。
在我看来,Zend 框架教程页面中显示的示例
if (!$temp->formIsValid())
{
$form = $this->getNextSubForm();
$this->view->form = $this->getForm()->prepareSubForm($form);
return $this->render('prepaid-funeral-plan');
}
检查整个表单是否有效,但导致用户提交数据之前在子表单的第二部分弹出验证错误的问题。
这是表单 processAction() 的完整代码
public function processAction()
{
if (!$form = $this->getCurrentSubForm()) {
// if there's no form data goto the beginning form stage
return $this->_forward('prepaid-funeral-plan');
}
if (!$this->subFormIsValid($form,$this->getRequest()->getPost()))
{
$this->view->form = $this->getForm()->prepareSubForm($form);
return $this->render('prepaid-funeral-plan');
}
if (!$this->formIsValid())
{
$form = $this->getNextSubForm();
$this->view->form = $this->getForm()->prepareSubForm($form);
return $this->render('prepaid-funeral-plan');
}
// Valid form!
// Render information in a verification page
$this->view->info = $this->getSessionNamespace();
$this->render('verification');
//Clear the session data!
Zend_Session::namespaceUnset($this->_namespace);
}
提前非常感谢!