/** * Upload a new GRF */ public function uploadAction() { $form = new App_Form(array('action' => $this->_helper->url->url(), 'method' => 'post', 'enctype' => 'multipart/form-data', 'elements' => array('grf_file' => array('file', array('label' => 'GRF-File', 'required' => true, 'destination' => UPLOADS_PATH, 'validators' => array(array('count', false, array('1')), array('extension', false, array('grf'))))), 'readme_file' => array('file', array('label' => 'Readme', 'required' => true, 'destination' => UPLOADS_PATH, 'validators' => array(array('count', false, array('1')), array('extension', false, array('txt'))))), 'terms_accepted' => array('checkbox', array('label' => 'Herby i confirm that the requirements noted in the terms & conditions are met', 'required' => true)), 'submit' => array('submit', array('label' => 'Upload GRF'))))); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $data = $form->getValues(); die(print_r($data)); } $this->view->form = $form; }
protected function _submitForm(App_Form $form, $request, $id = '') { //print_r($_POST); //$form = new App_Form_Table($this->_modelName); //$this->_setForm ( $form,$this->_model ); $id = trim($id); if ($request->getPost()) { if ($form->isValid($request->getPost())) { $isValid = true; if ($isValid) { try { if ($id == null) { $info = 7; } else { $info = 8; } $lastId = $form->save($id); $data['id'] = $lastId; if ($form->isInsearted()) { //echo "isInsearted"; //$this->_callBackAffterInsert ( $form, $data ); } elseif ($form->isUpdated()) { //$this->_callBackAffterUpdate ( $form, $data ); } if (trim($id) == '') { $id = $lastId; } return true; //$this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง"); // $this->view->infocode = $info; } catch (Exception $e) { $this->view->alert("เกิดปัญหาในการบันทึกข้อมูล ลองบันทึกข้อมูลอีกครั้ง"); $this->view->infocode = App_Env::sqlerror($e->getMessage()); return false; } } } else { $errors = $form->getMessages(); $messages = array(); foreach ($errors as $element_name => $error) { $element_messages = array(); foreach ($error as $elmessages) { $element_messages[] = "{$elmessages}"; } $messages[] = "{$element_name}:" . join(",", $element_messages); } $form_alert_message = join("<br/>", $messages); $this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง <br/>" . str_replace("'", "\\'", $form_alert_message)); return false; } } else { return false; // $this->view->infocode = "no post data"; } return false; }
/** * Create Modal dialog business logic * @param App_Form $form * @param array $options */ public function ajaxFormProcessor(App_Form $form, $options) { $params = $this->_getAllParams(); $subaction = isset($params['subaction']) ? $params['subaction'] : null; switch ($subaction) { case 'submit': if (!$form->isValid($params)) { $this->view->isValid = $form->isValid($params); $this->view->message = $form->getErrorMessages(); } else { $this->view->isValid = $form->isValid($params); $modelClass = $options['model']['class']; $modelMethod = $options['model']['method']; // persist method call_user_func(array($modelClass, $modelMethod), $params); $this->setMessage(self::$_translate->_($options['success']['message'])); $this->createAjaxButton($options['success']['button']['title'], $options['success']['button']['action']); if (isset($options['success']['redirect'])) { $this->view->redirect = $this->baseUrl . $options['success']['redirect']; } break; } default: $this->view->title = self::$_translate->_($options['title']); $this->createAjaxButton(self::$_translate->_($options['button']), "submit", $params, $options['url']); $this->view->form = $form->toArray(); } }