Jill 筆記
:::
:::
所有書籍
「Xoops新物件寫法」目錄
MarkDown
3. 新增活動表單
1. 前置作業
1-1 流程
2. 列出所有活動
3. 新增活動表單
3-1 新增到資料庫
3-2 編輯活動表單
4. 刪除活動
5. 修改前台首頁
3-2 編輯活動表單
Xoops新物件寫法 ========== 1. [action/AdminAction.class.php](https://github.com/tnjaile/ck_signup/commit/ce64f0435758cc390378047799fe13f82c8a5208#diff-0ece6698acedde7d0cebc5f0184eee02 "action/AdminAction.class.php") ```php // 新增 public function actions_form() { if (isset($_POST['send'])) { //XOOPS表單安全檢查 if (!$GLOBALS['xoopsSecurity']->check()) { $error = implode("
", $GLOBALS['xoopsSecurity']->getErrors()); redirect_header($_SERVER['PHP_SELF'], 3, $error); } if (isset($_POST['next_op'])) { if ($_POST['next_op'] == "add") { if ($this->_action->actions_add()) { $_message = "新增成功!"; } else { $_message = "新增失敗!"; } } } redirect_header($_SERVER['PHP_SELF'], 3, $_message); } $this->_tpl->assign('next_op', "add"); // 引入ckeditor $_content = ""; $ck = new CkEditor("ck_signup", "content", $_content); $ck->setHeight(200); $this->_tpl->assign('content_editor', $ck->render()); //套用formValidator驗證機制 $formValidator = new FormValidator("#myForm", true); $formValidator_code = $formValidator->render(); //加入Token安全機制 include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; $token = new \XoopsFormHiddenToken(); $token_form = $token->render(); $this->_tpl->assign("token_form", $token_form); $this->_tpl->assign('now_op', "actions_form"); $this->_tpl->assign('action', $_SERVER['PHP_SELF']); } ``` 2. [templates/op\_actions\_form.tpl](https://github.com/tnjaile/ck_signup/commit/ce64f0435758cc390378047799fe13f82c8a5208#diff-d369f31e3b6c321cd55704cc89c314fb "templates/op_actions_form.tpl") ```smarty
``` 3. [model/ActionsModel.class.php](https://github.com/tnjaile/ck_signup/commit/2bee4bd8630fec2436f8f8f77f2e78d2920f2c33#diff-3bb78de405a79c29f299a3eb70c5095f "model/ActionsModel.class.php") ```php // 欄位檢查 $this->_check = new ActionsCheck(); ``` 4. [check/ActionsCheck.class.php](https://github.com/tnjaile/ck_signup/commit/2bee4bd8630fec2436f8f8f77f2e78d2920f2c33#diff-2421bce8df55a4b5ae5c66ba9fa7eabc "check/ActionsCheck.class.php") ```php _message[] = '活動名稱不得為空!'; return false; } return true; } } ``` 5. 畫面 ![](http://120.115.2.101/~jaile/uploads/tad_book3/image/jillbase05.png)