我设法在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);
}
提前非常感谢!
答案 0 :(得分:0)
别担心,我设法弄明白了:))!
替换
public function formIsValid()
{
$data = array();
foreach ($this->getSessionNamespace() as $key => $info) {
$data[$key] = $info;
}
return $this->getForm()->isValid($data);
}
使用
public function formIsValid()
{
$data = array();
foreach ($this->getSessionNamespace() as $key => $info) {
$data[$key] = $info[$key];
}
return (count($this->getStoredForms()) < count($this->getPotentialForms()))? false : $this->getForm()->isValid($data);
}