开发者

Having problem with Zend Sub Form

开发者 https://www.devze.com 2023-03-11 02:39 出处:网络
I managed to get the example shown on the Zend Mutipage form tutorial http://framework.zend.com/manual/en/zend.form.advanced.html code working however im experiecing problem with the validation.

I managed to get the example shown on the Zend Mutipage form tutorial http://framework.zend.com/manual/en/zend.form.advanced.html code working however im experiecing problem with the validation.

The first part of the form loads fine, however when I clicks to "save and continue" button to the second part of the form it includes validation error messages. (Whic开发者_运维问答h is incorrect because validation errors should only pop up when user submit the second part of the sub form).

It seems to me the example shown in the Zend framework tutorial page

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

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

Checking if the whole form is valid or not, but it causing the problem that the validation error pop up in the second part of subform before the user submit the data.

Here is the complete code of the form 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);

}

Thanks so much in advance!


Don't worry about it, I managed to figure it out :)!

By replacing

  public function formIsValid()
    {
        $data = array();
        foreach ($this->getSessionNamespace() as $key => $info) {
            $data[$key] = $info;
        }

        return $this->getForm()->isValid($data);
    }

With

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号