Search code examples
phpzend-frameworkzend-formzend-form-elementview-helpers

Using Array html element naming convention with Zend Form inside View Script Decorator /


 $mon = new Zend_Form_Element_Checkbox('days[mon]');
 $tue = new Zend_Form_Element_Checkbox('tue');

how will I access "days[mon]" element inside view script for the form

$form = new Zend_Form();
$form->addElement($mon);

$form->setDecorator('form',array('ViewScript','viewscript'=>'form.phtml'));

I can easily access "tue" inside form.phtml

   $this->element->tue 

but how to access "days[mon]" ??


Solution

  • As far as I remember, for this puposes you should use subforms.

    For example:

            $mainForm = new Zend_Form();
            $daySubForm = new Zend_Form_SubForm();
            $mon = new Zend_Form_Element_Checkbox('mon');
    
            $daySubForm->addElement($mon);
            $mainForm->addSubForm($daySubForm, 'days');
    
            var_dump($mainForm->days->mon);