表單說明:https://www.ugm.com.tw/modules/tad_book3/page.php?tbdsn=142
<form action="xxx.php" method="post"> <!--用來控制程式流程--> <input type="hidden" name="op" value="{$DBV.op}"> <input type="hidden" name="sn" value="{$DBV.sn}"> <button type="submit" class="btn btn-default">送出</button> </form>
<div class="form-group"> <label>標題</label> <input type="text" class="form-control" id="title " name="title" value="{$DBV.title}" placeholder="標題"> </div>sort
<div class="form-group"> <label>排序</label> <input type="text" class="form-control" id="sort" name="sort" value="{$DBV.sort}" placeholder="排序"> </div>
<div class="form-group"> <label>網址</label> <input type="text" class="form-control" id="url" name="url" value="{$DBV.url}" placeholder="網址"> </div>
<div class="form-group"> <label>標題</label> <input type="password" class="form-control" id="password" name="password" placeholder="標題"> <p class="help-block">備註</p> </div>
<div class="form-group"> <label style="display:block;">啟用狀態</label> <input type='radio' name='enable' id='enable_1' value='1' {if $DBV.enable==1}checked{/if} > <label for='enable_1'>是</label> <input type='radio' name='enable' id='enable_0' value='0' {if $DBV.enable==0}checked{/if}> <label for='enable_0'>否</label> </div>
<div class="form-group"> <label style="display:block;">外連狀態</label> <input type='radio' name='target' id='target_1' value='1' {if $DBV.target==1}checked{/if} > <label for='target_1'>是</label> <input type='radio' name='target' id='target_0' value='0' {if $DBV.target==0}checked{/if}> <label for='target_0'>否</label> </div>
<div class="form-group"> <label><{$smarty.const._MD_UGMTRIP_PROD_KIND}></label> <select name="kind" class="form-control" size="1"> <{$DBV.kind_option}> </select> </div>
kind程式端
#定義常用變數 $TBL['name']="show_prod";//資料表名稱 $TBL['kind']="kind_prod";//分類
op_form()
$DBV['kind'] = (isset($DBV['kind'])) ? $DBV['kind'] : ""; $DBV['kind_option'] = get_kind_prod_option($DBV['kind']);
######################################## # 得到商品類別選項 ######################################## function get_kind_prod_option($kind="") { global $mysqli,$smarty,$TBL; $sql = "select sn,title from `show_kind` where `kind`='{$TBL['kind']}' and `enable`='1' "; $result = $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate)); $options=""; while($row = $result->fetch_assoc()) { #過濾撈出資料 $row['sn'] = intval($row['sn']); //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES); // 轉換雙引號和單引號 $selected = ($kind == $row['sn'])?" selected":""; $options .="<option value='{$row['sn']}'{$selected}>{$row['title']}</option>\n"; } return $options; }
<!-- 摘要--> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label>摘要</label> <textarea class="form-control" rows="5" id="summary" name="summary">{$DBV.summary}</textarea> </div> </div> </div>內容(網頁編輯器)
<script src="{$smarty.const.WEB_URL}/class/ckeditor/ckeditor.js"></script> <!-- 內容--> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label>內容</label> <textarea class="form-control" rows="5" id="content" name="content">{$DBV.content}</textarea> </div> </div> </div> <script> CKEDITOR.replace( 'content' ); </script>
<script src="{$smarty.const.WEB_URL}/class/My97DatePicker/WdatePicker.js" type="text/javascript"></script> <div class="col-md-3"> <div class="form-group"> <label>日期</label> {$DBV.date} </div> </div>
<div class="row"> <div class="col-md-9"> <div class="form-group"> <label>上傳圖片</label> <input name='file' type="file" id="file" class="form-control" accept="image/*" > </div> </div> {if $DBV.file_name} <div class="col-md-3"> <img src="{$DBV['file_name']}" alt="{$DBV.title}" class="img-responsive"> </div> {/if} </div>