一、自定義表單添加提交時間
添加“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>