:::

3-1 新增到資料庫

  1. action/AdminAction.class.php
    // 新增
        public function actions_form()
        {
            if (isset($_POST['send'])) {
                //XOOPS表單安全檢查
                if (!$GLOBALS['xoopsSecurity']->check()) {
                    $error = implode("<br />", $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
    <input type="hidden" name="next_op" value="<{$next_op}>">
  3. model/ActionsModel.class.php
    // 欄位檢查
    $this->_check = new ActionsCheck();
    
    

     

  4. check/ActionsCheck.class.php
    <?php
    //驗證類
    class ActionsCheck extends Check
    {
    // 新增時要做檢查(範例)
    public function addCheck(Model &$_model)
    {
    if (self::isNullString($_POST['title'])) {
    $this->_message[] = '活動名稱不得為空!';
    return false;
    }
    return true;
    }
    }
    
    
  5. 畫面