# DEDEcms自定义表单显示提交时间、添加提交时间、获取ip的方法

*Published:* 2023-10-22
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年10月22日，已超过 180天没有更新



首先修改plus/diy.php,在大概69行的地方找到：

```
if($fieldinfo[1] == 'textdata')  
{  
${$fieldinfo[0]} = FilterSearch(stripslashes(${$fieldinfo[0]}));  
${$fieldinfo[0]} = addslashes(${$fieldinfo[0]});  
}
```

在这段代码的下面添加：

```
if($fieldinfo[0] == 'oip'){
    ${$fieldinfo[0]}=GetIP();
}
if($fieldinfo[0] == 'otime'){
    ${$fieldinfo[0]}=date("Y-m-d H:i:s");
}
if($fieldinfo[0] == 'ourl'{
    ${$fieldinfo[0]}=$_SERVER['HTTP_REFERER'];
}
```

然后在自定义[表单](https://www.xarjtc.com/tag/%e8%a1%a8%e5%8d%95 "查看表单此标签更多文章")里添加字段

IP地址:oip

提交时间:otime

来源路径:ourl

字段名称一定要和diy.php添加的字段名一致

注意：新增表单字段之后，必须要更新一下表单中 dede\_fields 和 dede\_fieldshash 这两项的值，很多站长会忽略这个问题，导致后台无法接收新增字段的内容。

在表单中调取:

```
<input type="hidden" name="oip" id="oip" value="">
<input type="hidden" name="otime" id="otime" value="">
<input type="hidden" name="ourl" id="ourl" value="">
```

type="hidden" 标签可以把这两个表单隐藏起来，不会影响代码执行。

这样用户执行提交操作，后台就会自动获取用户IP地址和当前的时间还有提交的页面路径。

一、在自定义表单中添加字段

添加时间字段 timesj

二、在调用表单的页面中加入

```
<input name="timesj" value="" type="hidden" id="timesj" style="width:250px" class="intxt">
<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("timesj").value=str;
}
</script>
```

或者

```
<input type="hidden" name="timesj" id="timesj" value="{dede:php} echo $showtime=date('Y-m-d H:i:s');{/dede:php}">
```

此种方法好像生成的时间是静态的。

或者

```
<input type='hidden' name='timesj' id='timesj'/>
<script  language="javascript" type="text/javascript">var wdtime= new Date(); document.getElementById("timesj").value=wdtime.toLocaleString(); </script>
```

以上表单中使用了type=hidden，所以是隐藏模式。

三、在系统模板中添加

plus/diy\_list.htm 42的else前面或后面加入

```
if($fielddata[1]=='datetime')
{
    $fields[$field] = GetDateTimeMk($fields[$field]);
}
```

经过以上三步的处理，用户在前台填表后，管理后台就能看到用户添加的时间了。