Hello everyone, I am having some trouble with embedded forms and removal of these. I have a form that represents an image. Many images can belong to an image group. I have created a form that embeds many image forms into one image group form.
Each embedded image form has a checkbox widget, so when checked, it is processed for deletion by the form. The form allows for a new image to be uploaded to the group, again through an embedded form. My problem is, that during the transaction, the image to be deleted is deleted, but immediately after, I am seeing a blank insert statement being run. If I delete the line that calls Doctrine_Core::...delete(), the problem goes away. Can anyone see where I am going wrong? Thanks all, Richard Code is below: -- Image Group Form: -- class ImageCollectionGroupForm extends ImageGroupForm { protected $scheduleForDeletion; public function configure() { if (!$businessAccount = $this->getOption('business_account')) { throw new InvalidArgumentException('You must provide a business account object.'); } parent::configure(); $this->useFields( array( 'name', 'description' ) ); $image = new Image(); $image->ImageGroup = $this->getObject(); $newImage = new ImageForm($image, array('business_account' => $businessAccount)); $this->embedForm('newImage', $newImage); $currentImages = new ImageCollectionForm(array(), array('image_group' => $this->getObject(), 'business_account' => $this- >getOption('business_account'))); $this->embedForm('currentImages', $currentImages); } public function doBind(array $values) { foreach ($values['currentImages'] as $i => $image) { if (isset($image['delete'])) { $this->scheduleForDeletion[$i] = $image['id']; } } parent::doBind($values); } protected function doUpdateObject($values) { if (count($this->scheduleForDeletion)) { foreach ($this->scheduleForDeletion as $index => $id) { unset($values['currentImages'][$index]); unset($this->embeddedForms['currentImages'][$index]); unset($this->validatorSchema['currentImages'] [$index]); Doctrine_Core::getTable('Image')->findOneById($id)- >delete(); } } parent::doUpdateObject($values); } public function saveEmbeddedForms($con = null, $forms = null) { if (null === $forms) { $newImage = $this->getValue('newImage'); $forms = $this->embeddedForms; foreach ($this->embeddedForms['newImage'] as $name => $form) { if (!isset($newImage[$name]) || empty($newImage[$name])) { unset($forms['newImage'][$name]); } } if (!count($forms['newImage'])) { unset($forms['newImage']); } } return parent::saveEmbeddedForms($con, $forms); } } -- Image Form: -- class ImageCollectionForm extends sfForm { public function configure() { if (!$imageGroup = $this->getOption('image_group')) { throw new InvalidArgumentException('You must provide an image group object.'); } $imageGroup = $this->getOption('image_group'); foreach ($imageGroup->getImages() as $i => $image) { $form = new ImageForm($image, array('business_account' => $this->getOption('business_account'))); $this->embedForm($i, $form); } } } -- -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com 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 symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en