protected function processForm(sfWebRequest $request, CompanyForm $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { try { $isNew = $form->isNew(); $company = $form->save(); } catch (Doctrine_Validator_Exception $e) { $this->getUser()->setFlash('error', $e->getMessage()); return sfView::SUCCESS; } $this->getUser()->setFlash('success', $isNew ? 'The item has been created successfully' : 'The item has been updated successfully', true); if ($request->hasParameter('save_and_add')) { $this->redirect('@company_new'); } else { $this->redirect(array('sf_route' => 'company_edit', 'sf_subject' => $company)); } } else { $this->getUser()->setFlash('error', 'Please check the values entered in the form', false); } }
/** * @author : ELGUENNUNI Sohaib, s.elguennuni@gmail.com */ public function addcompanyAction() { $this->title = 'update Company'; $form = new CompanyForm(); $id = $this->_companyMemberModel->getCompany(App_Utilities::getIdMember()); if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $data = $form->getValues(); $fullFilePath = $form->logo->receive(); $pathparts = pathinfo($form->logo->getFileName()); $data['logo'] = $pathparts['basename']; $this->_companyModel->updateCompany($data, $id); $this->_redirect($this->view->url(array('module' => 'frontend', 'controller' => 'profile', 'action' => 'index', 'id' => App_Utilities::getIdMember()), 'default', true)); } else { $form->populate($formData); } } else { $form->populate($this->_companyModel->getCompany($id)); } $this->view->form = $form; }