public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         $message = "No Lead ID could be found.";
         $this->errorResponse->addMessage($message, "error");
         return $this->redirect()->toRoute('home', array('action' => 'add'), array('query' => array('msg' => 1)));
     }
     try {
         $submission = $this->getSubmissionMapper()->getSubmission($id);
     } catch (\Exception $ex) {
         $message = $ex->getMessage;
         $this->errorResponse->addMessage($message, "error");
         return $this->redirect()->toRoute('home', array('action' => 'index'), array('query' => array('msg' => 1)));
     }
     $form = new LeadForm();
     if ($submission && $submission instanceof SubmissionEntity) {
         if (!$submission->getLead()) {
             $message = "A Lead could not be found with the ID: \"{$id}\". Return to <a href=\"javascript:history.back()\" class=\"alert-link\">previous page</a>?";
             $this->errorResponse->addMessage($message, "error");
         }
         // echo "<pre>" . print_r($submission, true) . "</pre>";
         $form->bind($submission);
         $form->get('submit')->setAttribute('value', 'Edit Lead');
         $request = $this->getRequest();
         if ($request->isPost()) {
             $form->setData($request->getPost());
             if ($form->isValid()) {
                 $this->getSubmissionMapper()->saveSubmission($submission);
                 $message = "Lead Entry saved.";
                 $this->errorResponse->addMessage($message, "success");
                 // Redirect to View Lead
                 return $this->redirect()->toRoute('home', array('action' => 'view', 'id' => $id), array('query' => array('msg' => 1)));
             } else {
                 $message = array("You have invalid Form Entries.");
                 $this->errorResponse->addMessages(null, $message, $form->getMessages());
             }
         }
     } else {
         $message = "A Lead could not be found with the ID: \"{$id}\". Return to <a href=\"javascript:history.back()\" class=\"alert-link\">previous page</a>?";
         $this->errorResponse->addMessage($message, "error");
     }
     return array('id' => $id, 'form' => $form);
 }
 public function update($id, $data)
 {
     $result = null;
     $data['id'] = $id;
     $submission = $this->getSubmissionMapper()->getSubmission($id);
     $form = new LeadForm();
     $form->bind($submission);
     $form->setData($data);
     if ($form->isValid()) {
         $id = $this->getSubmissionMapper()->saveSubmission($submission);
     } else {
         return $this->errorResponse->errorHandler(400, "Invalid Submission.");
     }
     if ($id) {
         $result = $this->get($id);
     }
     return $result;
 }