【问题标题】:Having problem with Zend Sub FormZend 子表单有问题
【发布时间】:2011-06-06 03:18:08
【问题描述】:

我设法获得了 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);

}

提前非常感谢!

【问题讨论】:

    标签: zend-framework zend-form zend-validate


    【解决方案1】:

    别担心,我已经弄明白了:)!

    通过替换

      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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      相关资源
      最近更新 更多