public function processAction()
 {
     if (!$this->_request->isXmlHttpRequest() || !$this->_request->isPost()) {
         $this->_redirect('/admin/forms/');
     }
     $return = array();
     $formGateway = new Forms_Model_FormGateway();
     $form = $formGateway->getForm('ModifyForm');
     if ($form->isValid($this->_request->getPost())) {
         $form = $formGateway->create($form->getValues());
         $form->save();
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->setNamespace('notifications')->addMessage('Form updated.');
         if ($this->_request->getParam('close') == 1) {
             $return['redirect']['location'] = '/admin/forms/';
         } else {
             $return['notification']['target'] = '.notifications';
             $return['notification']['content'] = $this->view->displayMessages(true);
         }
     } else {
         $return['formErrors'] = $form->getMessages();
     }
     //$return['redirect']['location'] = '/admin/forms';
     $this->_helper->json->sendJson($return);
 }
Пример #2
0
 public function handleCode($name, array $params, $content)
 {
     if (!isset($params['name'])) {
         return;
     }
     // Do some initialization
     $this->init();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $formGateway = new Forms_Model_FormGateway();
     $form = $formGateway->generateForm($params['name'], $request->getRequestUri());
     if ($form == null) {
         return;
     }
     if (isset($params['id'])) {
         $form->setAttrib('id', $params['id']);
     }
     if ($request->isXmlHttpRequest() && $request->isPost()) {
         if ($form->getElement('form_id')->getValue() == $request->getParam('form_id')) {
             if ($form->isValid($request->getPost())) {
                 $result = $formGateway->processForm($form);
                 $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
                 $flashMessenger->setNamespace('notifications')->addMessage('Form Submitted.');
                 $return['notification']['target'] = '#' . $form->getName() . ' .notifications';
                 $return['notification']['content'] = $this->view->displayMessages(true);
             } else {
                 $return['formErrors'] = $form->getMessages();
             }
             $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
             $json->sendJson($return);
         }
     }
     $this->view->form = $form;
     return $this->view->render('helpers/customForm.phtml');
 }