2008年7月31日星期四

Re: [fw-mvc] Problems with subForms

-- Axel Wüstemann <awu@qbus.de> wrote
(on Thursday, 31 July 2008, 03:42 AM -0700):
> For an event registration I need a registration form n-times, as n is the
> count of sessions or subevents of a main event.

<snip>

> Then I create an empty form with Zend_Form and add the n SubForms to it:
>
> foreach($aSessions as $aSession) {
> $oForm->addSubForm($oSubForm, 'session_'.$aSession['EVENT_ID']);
> }
>
> What I get ist: all Subforms will have the same Id:

You need to clone the sub form in each iteration; otherwise, the same
object is used, so whichever sub form name is registered last wins. Try
this instead:

foreach($aSessions as $aSession) {
$clone = clone $oSubForm;
$oForm->addSubForm($clone, 'session_'.$aSession['EVENT_ID']);
}

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: