0

Zend Mutipage フォーム チュートリアルhttp://framework.zend.com/manual/en/zend.form.advanced.htmlコードに示されている例を取得することができましたが、検証で問題が発生しました。

フォームの最初の部分は正常に読み込まれますが、フォームの 2 番目の部分で [保存して続行] ボタンをクリックすると、検証エラー メッセージが表示されます。(ユーザーがサブフォームの 2 番目の部分を送信したときにのみ検証エラーがポップアップするため、これは正しくありません)。

Zendフレームワークのチュートリアルページに示されている例のようです

  if (!$temp->formIsValid())
                    {

                        $form = $this->getNextSubForm();
                        $this->view->form = $this->getForm()->prepareSubForm($form);
                        return $this->render('prepaid-funeral-plan');
                    }

フォーム全体が有効かどうかを確認しますが、ユーザーがデータを送信する前に、サブフォームの 2 番目の部分で検証エラーがポップアップするという問題が発生します。

フォーム 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);

}

よろしくお願いします!

4

1 に答える 1

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);
}
于 2011-06-06T07:15:28.987 に答える