在這里給大家舉個例子操作流程如下
- 文件結構如下:
enroll.php文件在 plus文件下
enroll.htm文件在templets/plus 文件夾下
adenroll.php文件在dede文件夾下
adenroll.html文件dede/templet文件夾下
- sql文件如下:
CREATE TABLE IF NOT EXISTS `dede_enroll` (`id` int(4) NOT NULL auto_increment,`name` varchar(20) NOT NULL,`mail` varchar(30) NOT NULL,`tag` tinyint(1) NOT NULL default '0',PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;INSERT INTO `dede_plus` (`aid`, `plusname`, `menustring`, `mainurl`, `writer`, `isshow`, `filelist`) VALUES(30, '網上報名', '<m:item name=''網上報名'' link=''adenroll.php'' rank=''plus_網上報名'' target=''main'' />', '', 'g1000', 1, '');
設置了 兩個字段 姓名和郵箱 tag字段是標示是否錄取 1為錄取
第一個insert語句是添加到后臺管理
第二個insert語句是添加到前臺導航欄
- enroll.php文件代碼:
<?php//*******要先包含common.inc.php 然后 session_start(); 否則取不到session的值//*******因為common.inc.php 有關于session路徑的配置include_once dirname(__FILE__).'./../include/common.inc.php';//包含配置文件session_start();require_once DEDEINC."/arc.partview.class.php";//包含partiew類//*****實例化 這個類的作用是得到頭部導航欄和尾部信息 若不需要可以使用dedetemplate.class.php 這個類$pv = new PartView();if($_POST){if( CheckEmail($_POST['mail'])==false){//驗證郵箱 方法在common.func.php 公用函數ShowMsg('郵箱格式錯誤','-1');exit();}if($_POST['name']==""){ShowMsg('用戶名不能為空','-1');exit();}else{$name=htmlspecialchars($_POST['name']);}if($_SESSION['dd_ckstr']!=strtolower($_POST['validation'])){//驗證 驗證碼 必須轉換成小寫ShowMsg('驗證碼錯誤',-1);exit();}$sql="insert into `cms_enroll`(name,mail) values('$name','$_POST[mail]')";//********$db可直接使用 系統自動實例化了dedesql.class.php$affected = $db->ExecuteNoneQuery2($sql);//執行一條語句 返回影響值if($affected){ShowMsg('報名成功',-1);}}else{$pv->SetTemplet(DEDETEMPLATE.'/plus/enroll.htm');//設置模板$pv->Display();//顯示頁面}?>
- enroll.htm文件代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"><head><title>{dede:global.cfg_webname/}-在線報名</title><link href="{dede:global.cfg_templeturl/}/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" /></script></head><body>{dede:include filename="../default/head.htm"/}<!-- 包含頭部 --><blockquote style="margin:50px auto" ><form method="post" action="">姓 名:<input type="text" size=30 name="name" />郵 箱:<input type="text" size=30 name="mail" /><!--vdimgck.php 是驗證碼-->驗證碼:<input type="text" name="validation" /><img src="../../include/vdimgck.php" /><input name="encoll" type="submit" value="報名" /></form></blockquote>{dede:include filename="../default/footer.htm"/}<!-- 包含尾部 --></body></html>
- adenroll.php文件代碼:
<?phprequire_once(dirname(__FILE__).'/config.php');//后臺配置文件 檢查登陸 配置信息require_once(DEDEINC."/datalistcp.class.php");//包含分頁類if($_GET['action']&&$_GET['id']){if($_GET['action']=='pass'){//各種操作$db->ExecuteNoneQuery("update cms_enroll set `tag`=1 where id='$_GET[id]'");ShowMsg('錄取成功','adenroll.php');}if($_GET['action']=='nopass'){$db->ExecuteNoneQuery("update cms_enroll set `tag`=0 where id='$_GET[id]'");ShowMsg('取消錄取','adenroll.php');}if($_GET['action']=='delete'){$db->ExecuteNoneQuery("delete from cms_enroll where id='$_GET[id]'");ShowMsg('刪除成功','adenroll.php');}}else{$dl = new DataListCP();$dl->pageSize = 10;//每頁顯示10條$dl->SetTemplate('./templets/adenroll.htm');//載入模板$sql="select * from cms_enroll";$dl->SetSource($sql);//執行sql 不能與$dl->SetTemplate 顛倒$dl->Display();//顯示頁面}?>
- adenroll.html文件代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"><head><title>在線報名管理</title><link href='img/base.css' rel='stylesheet' type='text/css' /><style type="text/css">th,td{text-align:center;border:1px #D1DDAA solid;font-size:15px;}th{background:#E6F8B7;}table{margin-top:20px;}</style></head><body><table width="90%" border="0" cellpadding="0" cellspacing="0" align="center"><tr><th>姓名</th><th>E-mail</th><th>狀態</th><th>操作</th></tr><!-- 循環得到結果 -->{dede:datalist}<tr><td>{dede:field.name /}</td><td>{dede:field.mail /}</td><td>{dede:if field.tag==0}未錄取{else}<font color="red">已錄取</font>{/dede:if}</td><td> <a href="adenroll.php?action=pass&id={dede:field.id /}">[錄取]</a>|<a href="adenroll.php?action=nopass&id={dede:field.id /}">[不通過]</a>|<a href="adenroll.php?action=delete&id={dede:field.id /}">[刪除]</a></td></tr>{/dede:datalist}</table><!-- 分頁標簽 --><p style="text-align:center;font-size:15px;">{dede:pagelist listitem="info,index,end,pre,next,pageno" listsize="5"/}</p></body></html>


