So you want to merge two or more of your Zend forms into one, right?
This is really easy to do, actually...
First of all, get a blank form:
$form = new Application_Form_UserInformation();
Then, get the other form(s):
$form_append = new Application_Form_UserAddress();
All you have to do is take all the elements from the other form(s) and add them to the first one!
$form->addElements($form_append->getElements());
You can still remove elements or add any by using addElement() or removeElement(). However, watch out for element names! If elements from two separate forms have the same one, the first you set will overwrite the others. This is useful for submit buttons, for example.
Be sure to always have your submission button at the end of your form, before sending it to your view:
$form->submit->setOrder(999);
$this->view->form = $form;
Piece of cake, told you so!
No comments:
Post a Comment