本文主要是介绍Web_PHP_DedeCMS_利用表单使用评论功能;,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
功能说明:利用DedeCMS自定义表单,实现在线用户评论功能;
=>表单:数据收集-数据提交-数据保存
<form name="pjform" action="/plus/diy.php" enctype="multipart/form-data" method="post"><input type="hidden" name="action" value="post" /><input type="hidden" name="diyid" value="1" /><input type="hidden" name="do" value="2" /><div class="tx_wrap">留言评价:<br /><textarea name='lypj' id='lypj' class="tx"></textarea></div><div class="tj_wrap"><div class="tj_name">昵称:<input type="text" name='hzmz' id='hzmz' class="tj_tx" /><input type='text' name='myd' id='myd' class="tj_tx" value='0' style="display:none;" /></div><input type="submit" name="submit" value="提 交" class='tj_btn' style="cursor:pointer;" /></div><input type="hidden" name="dede_fields" value="hzmz,text;myd,int;lypj,multitext" /><input type="hidden" name="dede_fieldshash" value="6c1e9a4f081e584e020e47fcc1ab994d" />
</form>
=>页面:数据获取-数据处理-数据显示
<div><?php// 数据获取-数据处理-数据显示 // 数据获取$con = mysql_connect("localhost","root","");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("wjtnbdb", $con);mysql_query("SET NAMES GBK");//$result = mysql_query("SELECT * FROM dede_diyformtnbshpj WHERE ifcheck=1 order by id desc");$result = mysql_query("SELECT * FROM dede_diyformhzpj order by id desc");// 数据处理 $records = mysql_num_rows($result); //echo '->records'.$records.'<br/>'; $pagesize = 5; $pages = 0; if($records != 0 ) { switch ($records % $pagesize) { case 0: $pages = $records/$pagesize; break; case 1: case 2: case 3: case 4: $pages = floor($records/$pagesize)+1; break; } }//echo '->pagesize'.$pagesize.'<br/>';//echo '->pages'.$pages.'<br/>';// 数据显示 $cursor = 0; $ulnum=0; while($row = mysql_fetch_array($result)){ if($cursor % $pagesize == 0) { $ulnumvalue = floor($cursor / $pagesize)+1; if($ulnumvalue == 1) { $ulclass = 'style="display: block;"'; }else { $ulclass = 'style="display: none;"'; } echo '<ul id="ul'.$ulnumvalue.'" '.$ulclass.'>'; } $cursor++; echo '<li id="li'.$cursor.'">'; echo '<div class="wrap01">'; echo '<div class="name">'.$row['hzmz'].'</div>'; echo '<div class="manyidu">总体满意度:<span>★</span><span>★</span><span>★</span><span>★</span><span>★</span></div>'; echo '<div class="num">(0)</div>'; echo '<a class="zan" href="javascript:void(0);" target="_parent"></a>'; echo '</div>'; echo '<p>'.$row['lypj'].'</p>'; echo '</li>'; if($cursor % $pagesize == 0) { echo '</ul>'; } }mysql_close($con);?>
</div>
<div class="page"><?php if($pages != 0) { for($num = 1; $num <= $pages; $num++) { if($num == 1) { $class = 'class="active"'; }else { $class = ''; } if($num == 1 && $pages > 1) {echo '<span id="prespan" style="cursor: pointer; display: none;"><a οnclick="prepage('.$pages.');" target="_parent">上一页</a></span>';}echo '<span id="pagespan'.$num.'" style="margin: 5px;padding: 5px;border: 1px solid #CCC;"'.$class.'>'; echo '<a style="color: #666;cursor: pointer;" οnclick="pagenumclick('.$num.', '.$pages.');" target="_parent">'.$num.'</a>'; echo '</span>'; if($num == $pages && $pages > 1) {echo '<span id="nextspan" style="cursor: pointer;"><a οnclick="nextpage('.$pages.');" target="_parent">下一页</a></span>';}} } ?>
</div>
=>js脚本:
<script type="text/javascript">// 前者var lastpage = 1;// 切换function switchpage(pagenum, pages) {// 恢复前者document.getElementById("pagespan" + lastpage).className = "";document.getElementById("ul" + lastpage).style.display = "none";// 保留状态lastpage = pagenum;// 设置当下document.getElementById("pagespan" + pagenum).className = "active";document.getElementById("ul" + pagenum).style.display = "block";// 显示上页if (pagenum != 1) {document.getElementById("prespan").style.display = "inline";} else {document.getElementById("prespan").style.display = "none";}// 显示下页if (pagenum == pages) {document.getElementById("nextspan").style.display = "none";} else {document.getElementById("nextspan").style.display = "inline";}}// 翻页function pagenumclick(pagenum, pages) {// 切换switchpage(pagenum, pages);}// 上页function prepage(pages) {var pagenum = lastpage - 1;switchpage(pagenum, pages);}// 下页function nextpage(pages) {var pagenum = lastpage + 1;switchpage(pagenum, pages);}window.onload = function () {// form disposevar formpj = document.forms["pjform"];formpj.reset();formpj.onsubmit = function () {var isSubmit = true;var hasError = false;var errArray = new Array();var hzmz = document.getElementById("hzmz");var lypj = document.getElementById("lypj");if (hzmz.value == "") {hzmz.style.borderColor = "red";hzmz.style.bgColor = "blue";hzmz.title = "请输入姓名!";hasError = true;errArray.push(hzmz);} else {hzmz.style.borderColor = "";hzmz.style.bgColor = "";hzmz.title = "";hasError = false;}if (lypj.value == "") {lypj.style.borderColor = "red";lypj.style.bgColor = "blue";lypj.title = "请输入留言!";hasError = true;errArray.push(lypj);} else {lypj.style.borderColor = "";lypj.style.bgColor = "";lypj.title = "";hasError = false;}if (hasError && errArray.length > 0) {isSubmit = false;errArray[0].focus();}return isSubmit;}}
</script>
这篇关于Web_PHP_DedeCMS_利用表单使用评论功能;的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!