예제 #1
0
파일: Form.php 프로젝트: hugi2002/mylibrary
 public function submit($request, $id = '')
 {
     $id = trim($id);
     $form = $this;
     if ($request->getPost()) {
         //print_r( $request->getPost () );
         if ($form->isValid($request->getPost())) {
             $isValid = true;
             if ($isValid) {
                 try {
                     if ($id == null) {
                         $info = 7;
                     } else {
                         $info = 8;
                     }
                     if (method_exists($this->_model, 'setIsActive')) {
                         $form->addParam('IsActive', 1);
                     }
                     $lastId = $form->save($id);
                     echo $this->getView()->displayError($info);
                     return $lastId;
                 } catch (Exception $e) {
                     echo $this->getView()->displayError("เกิดปัญหาในการบันทึกข้อมูล ลองบันทึกข้อมูลอีกครั้ง");
                     echo $this->getView()->displayMsg(App_Env::sqlerror($e->getMessage()));
                     $this->getView()->infocode = App_Env::sqlerror($e->getMessage());
                 }
             }
         } else {
             $errors = $form->getMessages();
             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/>", $element_messages);
             echo $this->getView()->displayError($form_alert_message);
         }
     }
 }
예제 #2
0
 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;
 }