public function editAction() { $id = (int) $this->params('id'); if (!$id) { return $this->redirect()->toRoute('contact', array('action' => 'add')); } $contact = $this->getContactTable()->getContact($id); $form = new ContactForm(); $form->bind($contact); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $this->getContactTable()->saveContact($contact); // Redirect to list of contacts return $this->redirect()->toRoute('contact'); } } return array('id' => $id, 'form' => $form); }
public function editAction() { $id = (int) $this->params()->fromRoute('id', 0); $contact = $this->getContactTable()->getContact($id); $form = new ContactForm(); $form->bind($contact); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { $form->setInputFilter($contact->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $this->getContactTable()->saveContact($contact); //Redirect to contact list return $this->redirect()->toRoute('contact'); } } return array('id' => $id, 'form' => $form); }