#---- 商品表單
case "opForm":
opForm($sn);
break;
```
### 二、函數
1. opForm()
admin/main.php ```
########################################
# 函數說明
# 外部變數請用參數傳值方式或global
########################################
function opForm($sn = "") {
global $xoopsDB,$xoopsTpl,$module_name,$ugmKind,$xoTheme;
//----------------------------------*/
//抓取預設值
if (!empty($sn)) {
$row = get_ugm_module_tbl($sn, "cnu_show_prod");//取得某筆記錄資料
$pre = _EDIT;
$row['op'] = "opUpdate";//在表單中表示接下來流程
} else {
$row = array();
$pre = _ADD;
$row['op'] = "opInsert";//在表單中表示接下來流程
}
$row['form_title'] = $pre . _MD_CNUSHOW_PROD;
//預設值設定
$row['sn'] = (!isset($row['sn'])) ? "" : $row['sn'];
$row['kind'] = (!isset($row['kind'])) ? "" : $row['kind'];
$row['kind_option'] = $ugmKind->get_kindOption($row['kind']);
$row['title'] = (!isset($row['title'])) ? "" : $row['title'];
$row['youtube'] = (!isset($row['youtube'])) ? "" : $row['youtube'];
$row['summary'] = (!isset($row['summary'])) ? "" : $row['summary'];
$row['price'] = (!isset($row['price'])) ? "" : $row['price'];
#排序,新增取得最大排序,編輯則按資料庫決定
$row['sort'] = (!isset($row['sort'])) ? get_ugm_module_max_sort("sort", "cnu_show_prod"):$row['sort'];
//$row['amount'] = (!isset($row['amount'])) ? "" : $row['amount'];
$row['choice'] = (!isset($row['choice'])) ? "0" : $row['choice'];
$row['enable'] = (!isset($row['enable'])) ? "1" : $row['enable'];
$row['date'] = !isset($row['date']) ? date("Y-m-d H:i:s", xoops_getUserTimestamp(strtotime("now"))) : date("Y-m-d H:i:s", xoops_getUserTimestamp($row['date']));
//strtotime("now"):為目前主機的時間磋記,xoops_getUserTimestamp(strtotime("now"))):將時間磋記改為會員的時間磋記
$row['content'] = (!isset($row['content'])) ? "" : $row['content'];
//內容#資料放「content」
# ======= ckedit====
//$UserPtah="config"
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/ck.php")) {
redirect_header("http://www.tad0616.net/modules/tad_uploader/index.php?of_cat_sn=50", 3, _TAD_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/ck.php";
#---- 檢查資料夾
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck");
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck/image");
mk_dir(XOOPS_ROOT_PATH . "/uploads/{$module_name}/fck/flash");
$dir_name = $module_name . "/fck";
#----
$ck = new CKEditor($dir_name, "content", $row['content'], $module_name);
$ck->setHeight(300);
$row['content_editor'] = $ck->render();
#-------------------------------------
#上傳單張圖片
#----單檔圖片上傳
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir);//實體化
$name = "prod"; //表單欄位名稱
$col_name = "prod"; //資料表關鍵字
$col_sn = $row['sn']; //關鍵字流水號
$multiple = false; //單檔 or 多檔上傳
$accept = "image/*"; //可接受副檔名
$row['prod'] = $ugmUpFiles->upform($name,$col_name,$col_sn,$multiple,$accept);
#-----------------------------------
#上傳pdf型錄
$subdir = "prod"; //子目錄(前後不要有 / )
$ugmUpFiles = new ugmUpFiles($module_name, $subdir);//實體化
$name = "prodPdf"; //表單欄位名稱
$col_name = "prodPdf"; //資料表關鍵字
$col_sn = $row['sn']; //關鍵字流水號
$multiple = false; //單檔 or 多檔上傳
$accept = "application/pdf"; //可接受副檔名
$row['prodPdf'] = $ugmUpFiles->upform($name,$col_name,$col_sn,$multiple,$accept);
//-------------------------------*/
//----- 驗證碼 -----------------*/
if (!file_exists(XOOPS_ROOT_PATH . "/modules/tadtools/formValidator.php")) {
redirect_header("index.php", 3, _TAD_NEED_TADTOOLS);
}
include_once XOOPS_ROOT_PATH . "/modules/tadtools/formValidator.php";
$formValidator = new formValidator("#myForm", true);
$formValidator_code = $formValidator->render();
//-------------------------------*/
#小月曆
$xoTheme->addScript('modules/tadtools/My97DatePicker/WdatePicker.js');
$xoopsTpl->assign('row', $row);
}
```
### 三、樣板
1. templates/cnu\_show\_adm\_main.tpl ```
<{if $op == "opForm"}>
<{/if}>
```
2.