public function isValid($data) { $ndata = $data; if ($this->isArray()) { $key = $this->_getArrayName($this->getElementsBelongTo()); if (isset($data[$key])) { $ndata = $data[$key]; } } foreach ($this->_adapter->getRelations() as $name => $relation) { if ($this->_isIgnoredRelation($relation)) { continue; } if ($relation['type'] != CU_Form_Model::RELATION_MANY) { continue; } if (isset($ndata[$this->_getNewButtonName($name)]) || isset($ndata[$this->_getFormName($name)])) { if (isset($ndata[$this->_getFormName($name)]) && isset($ndata[$this->_getFormName($name)][$this->_getDeleteButtonName($name)])) { return false; } $cls = $this->_relationForms[$relation['model']]; if ($cls !== null) { $form = new $cls(); } else { $form = new CU_Form_Model(array('model' => $relation['model'])); } $form->setIsArray(true); $form->removeDecorator('Form'); $form->addElement('submit', $this->_getDeleteButtonName($name), array('label' => 'Delete')); $this->addSubForm($form, $this->_getFormName($name)); if (isset($ndata[$this->_getNewButtonName($name)])) { return false; } } $record = $this->getRecord(); foreach ($this->_adapter->getOneRecords($record, $name) as $rec) { $formName = $this->_getFormName($name, $rec); if (isset($ndata[$formName]) && isset($ndata[$formName][$this->_getDeleteButtonName($name, $rec)])) { $this->removeSubForm($formName); $this->_adapter->deleteRecord($rec); return false; } } } return parent::isValid($data); }