Hello

I read the thatsquality.com tutorial on Symfony-1.1 forms but apparently
their examples do not cover the saving of embedded forms. While trying it out
myself I found a solution but am still wondering if this is the intended way.

It seems a bit superfluous to me that I have to cache the names of the
embedded forms in $sub_forms to update them one by one myself although
symfony should be aware of them and update them in $main_form->bind()
automatically, or?

Do you have suggestions or pointers to better examples?

bye,

-christian-


    public function executeEdit() {
        // load data from database
        $invheader = InvheaderPeer::retrieveByPK( 
$this->getRequestParameter('id') );
            
        // create an empty form+subforms skeleton
        $sub_forms = array();
        $this->main_form = new InvheaderForm($invheader);
        foreach ($invheader->getMyinvlines() as $myinvline) { 
            $sub_form = new MyinvlineForm($myinvline);
            $sub_form_name = 'myinvline-' . $myinvline->getId();
            $sub_forms[$sub_form_name] = $sub_form;
            $this->main_form->embedForm($sub_form_name, $sub_form);
        }   
        
        if ($this->getRequest()->isMethod('post')) {
            $invheader_postdata = $this->getRequestParameter('invheader');
            
            // Update main form
            $this->main_form->bind($invheader_postdata);
            if ($this->main_form->isValid()) {
                $this->main_form->updateObject();
                $this->main_form->save();
                $this->getUser()->setFlash('message', 'main_form saved');
                
                // Update sub forms
                foreach ($sub_forms as $sub_form_name => $sub_form) {
                    $sub_form->bind($invheader_postdata[$sub_form_name]);
                    if ($sub_form->isValid()) {                    
                        $sub_form->updateObject();
                        $sub_form->save();
                        $this->getUser()->addFlash('message', "subform 
$sub_form_name saved");
                    }
                }
            }
        }
   
        // Auch bei Fehlern das "editSuccess" Template nehmen!
        return sfView::SUCCESS;
    }
    

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to