-- Stefan Gehrig <[EMAIL PROTECTED]> wrote
(on Tuesday, 19 August 2008, 11:13 AM +0200):
> I'm currently struggling with Zend_Form... I try to build a form that should
> include another form as a subform.
> This is what I've been doing so far in the init()-method of my form:
>
> $newPersonSubForm=new Zend_Form_SubForm(array(
> 'legend' => 'Neue Person',
> 'disableLoadDefaultDecorators' => true,
> 'disableTranslator' => true,
> 'decorators' => array(
> 'FormElements',
> array('HtmlTag', array('tag' => 'ol')),
> 'Fieldset')));
> $editForm=new Club_Person_Form_Edit();
> $editForm->removeDisplayGroup('buttons');
> $newPersonSubForm->addSubForm($editForm, 'newPerson-subform');
> $this->addSubForm($newPersonSubForm, 'newPerson');
>
> This works as expected: I get my normal form fields and then I get a
> fieldset named 'fieldset-newPerson' from the Zend_Form_Subform under which I
> get all my elemts from Club_Person_Form_Edit in array notation e.g.
> 'newPerson[firstName]'.
>
> The problem is, that the line
> $editForm->removeDisplayGroup('buttons');
Well, the prolem is that you added a _sub form_, not a display group.
Try using removeSubForm(). However, if you do that, you lose all
elements beneath it.
> does not work as expected. My 'Save' button is grouped in a display-group
> 'buttons' in Club_Person_Form_Edit, so I thought that I could remove those
> buttons just by removing the display group to avoid two 'Save' buttons being
> rendered.
>
> What am I doing wrong and is this a best practice at all??? Do I have to
> remove the elements inside the display-group one by one?
> And is there a way to avoid this 'hack' of creating a Zend_Form_SubForm and
> add the real form as a subform of this subform and still get the desired
> result (array notation of all elements in Club_Person_Form_Edit)?
>
> Thanks a lot and best regards
>
> Stefan
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/