很多朋友都遇到了DEDECMS自定义表单中地区二级联动后,调用联动字段时只显示地区代码13003其实是贵州省遵义市的系统联动类编号,要让其显示成贵州省遵义市其实也比较容易。
需要动3个文件。
第一个是根目录plus/diy.php。
第二个是上一个php对应的模板文件更目录下templates/plus/view_diyform.htm和list_diyform.htm(两个模板文件改法一样)。
提醒一下注意备份要修改的这几个文件。
现在开始了对于diy.php打开后找到elseif($action == ‘list’)这一行,再在它的下边找到
include_once DEDEINC.’/datalistcp.class.php’;下面加入
include_once(DEDEDATA.’/enums/nativeplace.php’);
include_once(DEDEINC.”/enums.func.php”);
这样两个,
同样找到elseif($action == ‘view’)这一行,也在
include_once DEDEINC.’/datalistcp.class.php’;下加入上边的红色两句
详细代码如下
elseif($action == ‘list’)
{
if(empty($diy->public))
{
showMsg(‘后台关闭前台浏览’, ‘javascript:;’);
exit();
}
include_once DEDEINC.’/datalistcp.class.php’;
include_once(DEDEDATA.’/enums/nativeplace.php’);
include_once(DEDEINC.”/enums.func.php”);
if($diy->public == 2)
{
$query = “select * from `{$diy->table}` order by id desc”;
}
else
{
$query = “select * from `{$diy->table}` where ifcheck=1 order by id desc”;
}
$datalist = new DataListCP();
$datalist->pageSize = 10;
$datalist->SetParameter(‘action’, ‘list’);
$datalist->SetParameter(‘diyid’, $diyid);
$datalist->SetTemplate(DEDEINC.”/../templets/plus/{$diy->listTemplate}”);
$datalist->SetSource($query);
$fieldlist = $diy->getFieldList();
$datalist->Display();
}
//list部分完
elseif($action == ‘view’)
{
if(empty($diy->public))
{
showMsg(‘后台关闭前台浏览’ , ‘javascript:;’);
exit();
}
if(empty($id))
{
showMsg(‘非法操作!未指定id’, ‘javascript:;’);
exit();
}
include_once DEDEINC.’/datalistcp.class.php’;
include_once(DEDEDATA.’/enums/nativeplace.php’);
include_once(DEDEINC.”/enums.func.php”);
if($diy->public == 2)
{
$query = “select * from {$diy->table} where id=’$id’ “;
}
else
{
$query = “select * from {$diy->table} where id=’$id’ and ifcheck=1″;
}
$row = $dsql->getone($query);
if(!is_array($row))
{
showmsg(‘你访问的记录不存在或未经审核’, ‘-1′);
exit();
}
$fieldlist = $diy->getFieldList();
include DEDEROOT.”/templets/plus/{$diy->viewTemplate}”;
}
?>
//view部分完
然后打开view_diyform.htm
找到<table class=’listtable’ cellspacing=”1″>一行
把下一行还是的到</table>之间的
<?php
echo ‘<tbody>’;
echo ‘<tr><td bgcolor=”#eeeeee” width=”20%”>id</td><td bgcolor=”#eeeeee”>’.$row['id'].’</td></tr>’;
$allowhtml = array(‘htmltext’);
foreach($fieldlist as $field=>$fielddata)
{
if($row[$field]==”) continue;
if($fielddata[1]==’img’)
{
$row[$field] = “<a href=’{$row[$field]}’ target=’_blank’><img src=’{$row[$field]}’/></a>\r\n”;
}
else if($fielddata[1]==’addon’)
{
$row[$field] = “<a href=’{$row[$field]}’ target=’_blank’><img src=’img/addon.gif’ border=’0′ /> 相关附件</a>”;
}
else
{
if(!in_array($fielddata[1], $allowhtml))
{
$row[$field] = htmlspecialchars($row[$field]);
}
}
echo ‘<tr><td bgcolor=”#ffffff”>’.$fielddata[0].’</td><td bgcolor=”#ffffff”>’.$row[$field].’</td></tr>’;
}
echo ‘</tbody>’;
?>
(也就是将那部分php代码)都删除掉,然后将下面的代码加进去。
<tbody>
<tr><td bgcolor=”#eeeeee” width=”20%”>id</td><td bgcolor=”#eeeeee”><?php echo $row['id']; ?></td></tr>
<tr><td bgcolor=”#eeeeee” width=”20%”>生日</td><td bgcolor=”#eeeeee”><?php echo $row['shengri']; ?></td></tr>
<tr>
<td>目前所在地:</td>
<td> 省份:
<?php
$places = GetEnumsTypes($row['nativeplace']);
echo ( isset($em_nativeplaces[$places['top']]) ? $em_nativeplaces[$places['top']] : ”);
?>
城市:
<?php
echo ( isset($em_nativeplaces[$places['son']]) ? $em_nativeplaces[$places['son']] : ”);
?></td>
</tr>
</tbody>