[Zend_Form][1.12.0] Form instance in session

For programming and general questions on Zend Framework

[Zend_Form][1.12.0] Form instance in session

Postby rclsilver on Mon Dec 03, 2012 8:54 pm

Hi!

i've a Zend_Form instance with subforms stored in the user session.

The first time that the page is displayed, the form is generated, stored in session and displayed. At this moment, all is working fine.

The second time the page is displayed, the form instance is recovered from session and displayed. In this case, i've a problem with subforms.

For example, i've the following code :
Code: Select all
   public function testAction() {
      if($this->getParam('flush', 'false') === 'true' || !isset($_SESSION['form'])) {
         $_SESSION['form'] = new Zend_Form();

         $platform = new Zend_Form_SubForm();
         $_SESSION['form']->addSubForm($platform, 'platform');

         $appli = new Zend_Form_SubForm();
         $_SESSION['form']->addSubForm($appli, 'appli');

         $step = new Zend_Form_Element_Text('__step');
         $step->setValue(1);
         $step->setLabel('step');
         $_SESSION['form']->addElement($step);

         $pfname = new Zend_Form_Element_Text('name');
         $pfname->setValue('platform name');
         $pfname->setLabel('platform name');
         $platform->addElement($pfname);

         $applinet = new Zend_Form_SubForm();
         $appli->addSubForm($applinet, 'net');

         $applinetaddr = new Zend_Form_Element_Text('addr');
         $applinetaddr->setLabel('Appli network address');
         $applinetaddr->setValue('localhost');
         $applinet->addElement($applinetaddr);
         
      }

      $this->view->form = $_SESSION['form'];

      // Process request
      if($this->getRequest()->isPost()) {
         if($this->view->form->isValid($_POST)) {
            $this->view->data = $this->view->form->getValues();
         }
      }
   }


When the form is displayed from the session ,the field appli[net][ipaddr] is renamed to appli[appli][net][ipaddr]... If i reload the page 3th time, the field name is now appli[appli][appli][net][ipaddr], etc... etc...

Anyone has an idean about the cause and/or the solution about this problem ?

Thank's a lot
rclsilver
 
Posts: 1
Joined: Mon Dec 03, 2012 8:48 pm

Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 6 guests