织梦表单留言添加时间、全选、提示信息、手机号验证、必填项等技巧


一、自定义表单添加提交时间

添加“time”属性

织梦cms表单留言添加时间

添加后如下图:

织梦留言添加时间2

在前台页面模板2个位置添加代码:

第一个:

<input name="time" value="" type="hidden" id="time" />

<script type="text/javascript">

window.onload = function(){

var nowDate = new Date();

var str = nowDate.getFullYear()+"-"+(nowDate.getMonth() + 1)+"-"+nowDate.getDate()+" "+nowDate.getHours()+":"+nowDate.getMinutes()+":"+nowDate.getSeconds();

document.getElementById("time").value=str;

}

</script>

第二个:在相应value值后面添加“;time;text”

织梦留言添加时间

添加字段

再新 

 

变更数据校验串:

 

 

 

查看源代码,找到字符串:

 

 

替换原先的字符串

保存,更新后,

,再留言测试,即可成功留言,时间在后台也显示了。

织梦自定义表单设置

备注:①若其他地方有同样的留言框,则需要在相应的前台页面进行代码修改。而因为后台的time属性已经添加,则不再后台设置。

   ②如果字段添加不显示,把原先在线留言信息截图,再增加新的自定义表单,信息和原先的的在线留言一样。即可

   ③

对应。

二、留言内容限制

① 手机号限定为11位

在plus/diy.php中添加下面代码:

//判断手机号码是否正确

if(!eregi("^1[0-9]{10}$",$tel))

{

showMsg('手机号码不对,请正确填写', '-1');

exit();

}

织梦自定义表单手机号限定

注意:上面的“tel”需要换成手机号的字符串。

② 增加姓名和手机号2项为必填项

1. 在plus/diy.php 的第 40行下加如下代码:

//增加必填字段判断

if($required!=''){

if(preg_match('/,/', $required)){

$requireds = explode(',',$required);

foreach($requireds as $field){

if($$field==''){

showMsg('带*号的为必填内容,请正确填写', '-1');

exit();

}

}

}else{

if($required==''){

showMsg('带*号的为必填内容,请正确填写', '-1');

exit();

}

}

}

织梦留言必填项设置

2、在模版的表单里加:

<input type="hidden" name="required" value="name, phone" />

注意:value值依据实际情况而设。

三、自定义表单增加全选、全不选功能

从/dede/templets找到diy_list.htm并打开:

1、在57行处colspan="3"改为colspan="5"

2、58行处添加以下代码:

<label><input type="button" name="select" onclick="selectAll()" value="全选"/></label>

<label><input type="button" name="select" onclick="selectAll1()" value="取消全选"/></label>

3、在后面加上js代码:(加到</body>前即可)

<script type="text/javascript">

function selectAll(){

var a = document.getElementsByTagName("input");

for(var i = 0;i<a.length;i++){

if(a[i].type == "checkbox") a[i].checked = true;

}

}

function selectAll1(){

var a = document.getElementsByTagName("input");

for(var i = 0;i<a.length;i++){

if(a[i].type == "checkbox") a[i].checked = false;

}

}

</script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM