:::

4-9 完整表單函數

  1. 最後完整版看起來像這樣:
    
    //顯示預設頁面內容
    function action_form()
    {
    
        global $xoopsTpl;
    
        include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
        $val = ['title' => '', 'action_date' => date('Y-m-d'), 'end_date' => date('Y-m-d 17:30:00'), 'enable' => '1', 'content' => ''];
    
        $form = new XoopsThemeForm('編輯活動', 'name', 'main.php', 'post', true);
        $form->addElement(new XoopsFormText('活動名稱', 'title', 40, 255, $val['title']), true);
    
        include_once XOOPS_ROOT_PATH . "/modules/tadtools/cal.php";
        $cal = new My97DatePicker();
        $cal->render();
        $action_date = new XoopsFormText('活動日期', 'action_date', 15, 255, $val['action_date']);
        $action_date->setExtra("onClick=\"WdatePicker()\"");
        $form->addElement($action_date, true);
    
        $end_date = new XoopsFormText('截止日期', 'end_date', 15, 255, $val['end_date']);
        $end_date->setExtra("onClick=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss', startDate:'%y-%M-%d 17:30:00'})\"");
        $form->addElement($end_date, true);
    
        $form->addElement(new XoopsFormRadioYN('使否啟用', 'enable', $val['enable']));
    
        include_once XOOPS_ROOT_PATH . "/modules/tadtools/ck.php";
        $ck = new CKEditor("tad_signup", "content", $val['content']);
        $ck->setHeight(350);
        $editor = $ck->render();
        $form->addElement(new XoopsFormLabel('活動內容', $editor));
    
        $form->addElement(new XoopsFormHidden('op', 'insert_action'));
        $Tray = new XoopsFormElementTray('', ' ', 'name');
        $Tray->addElement(new XoopsFormButton('', 'name', '清除', 'reset'));
        $Tray->addElement(new XoopsFormButton('', 'name', '送出', 'submit'));
        $form->addElement($Tray);
        $action_form = $form->render();
    
        $xoopsTpl->assign('action_form', $action_form);
    }
  2. 一開使用利用$val = []; 來設定預設值。
  3. 最後把產生的表單送至樣板檔

:::

書籍目錄

展開 | 闔起

https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D29%26tbdsn%3D876

計數器

今天: 1896189618961896
昨天: 2395239523952395
總計: 7917841791784179178417917841791784179178417917841