Example #1
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $form = new Model\Form();
     $form->getById($id);
     if (!isset($form->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/forms');
     }
     $this->prepareView('forms/edit.phtml');
     $this->view->title = 'Forms';
     $this->view->form_name = $form->name;
     $fields = $this->application->config()['forms']['Phire\\Forms\\Form\\FormObject'];
     $fields[1]['name']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new \Pop\Form\Form($fields);
     $this->view->form->setAttribute('id', 'form-form');
     $this->view->form->setIndent('    ');
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($form->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $form = new Model\Form();
             $form->update($this->view->form->getFields());
             $this->view->id = $form->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/forms/edit/' . $form->id);
         }
     }
     $this->send();
 }