public function addFieldProcessAction() { if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost()) { $this->_redirect('/admin/forms/'); } $return = array(); $formFieldGateway = new Forms_Model_FormFieldGateway(); $form = $formFieldGateway->getForm('CreateFormField'); if ($form->isValid($this->_request->getPost())) { $form = $formFieldGateway->create($form->getValues()); $fieldId = $form->save(); $formField = $formFieldGateway->fetchFormField($fieldId); $elementClass = 'Zend_Form_Element_' . ucfirst($formField->form_field_type); $element = new $elementClass($formField->form_field_name, $formField->form_field_attribs); if (is_array($formField->form_field_options) && !empty($formField->form_field_options)) { $element->addMultiOptions($formField->form_field_options); } $element->clearDecorators(); $element->addDecorator('Label'); $element->addDecorator('ViewHelper'); $flashMessenger = $this->_helper->getHelper('FlashMessenger'); $flashMessenger->setNamespace('notifications')->addMessage('Field Added!'); $return['notification']['target'] = '.notifications'; $return['notification']['content'] = $this->view->displayMessages(true); $return['append']['target'] = '#formContainer'; $return['append']['content'] = '<li>' . $element->renderLabel() . $element->renderViewHelper() . '<div class="sortHandle"></div></li>'; $return['callback'] = '$("#add-field-dialog").dialog("close");$("#formContainer .message").remove();'; } else { $return['formErrors'] = $form->getMessages(); } $this->_helper->json->sendJson($return); }
/** * Fetch form * * @param int|string $id Location id * @return Forms_Model_Form|null */ public function fetchForm($id) { $this->checkAcl('read'); $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database'); /** * @todo Need to come up with a solution for caching for fetchForm * Issue is that the $id could be a string or an int so we need to * cache based on both.....a form called "This form" with an id of 2 * should be cached once and be retrieved by either option id or name * * Partial solution in place. Not caching basic form record retrieval * but all fields are cached and its all cached based on form_id */ $table = new Forms_Model_DbTable_Form(); $select = $table->select(); $select->where($this->_createFormCondition($id)); $row = $table->fetchRow($select); if (null === $row) { return null; } $cacheKey = md5('form_' . $row->form_id); if (!($form = $cache->load($cacheKey))) { $form = new Forms_Model_Form($row, $this); // Get the products categories $notificationRowset = $row->findDependentRowset('Forms_Model_DbTable_FormNotification')->toArray(); $form->formNotifications = $notificationRowset; $formFieldGateway = new Forms_Model_FormFieldGateway(); $form->formFields = $formFieldGateway->fetchFormFields($row->form_id); $cache->save($form, $cacheKey, array('forms')); } return $form; }