织梦自定义表单联动地区后台显示为数字的真正解决方法亲测可用
作者:king 日期:2023-04-30 分类:CMS教程
网络上有类似的文章,但是都是不全,错误的方法。以下是本站长整理出来亲身验证无误的方法.
1.在\dede\templets\diy_list.htm 找到(大约在41行):
else if($fielddata[1]=='addon')
{
$fields[$field] = "<a href='{$fields[$field]}' target='_blank'><img src='images/channeladd.gif' border='0' /> 其它附件</a>";
}
在下面加入:
//联动类型显示修正开始
else if($fielddata[1]=='stepselect')
{
$db->Execute('me',"SELECT * FROM `dede_stepselect` WHERE egroup='{$field}'");
while($arr = $db->GetArray(me))
{
$egroup = $arr['egroup'];
}
$fields[$field] = Getenums("{$fields[$field]}",$egroup);
}
//联动类型显示修正结束www.80zhan.com织梦模板下载
继续找到:
{/dede:datalist}
在下面加入:
<?php
function Getenums($evalue = 0, $egroup)
{
if (!isset($GLOBALS['em_' . $egroup . 's'])) {
$cachefile = DEDEDATA . '/enums/' . $egroup . '.php';
if (!file_exists($cachefile)) {
require_once DEDEINC . '/enums.func.php';
WriteEnumsCache();
}
if (!file_exists($cachefile)) {
return '';
} else {
require_once $cachefile;
}
}
if ($evalue >= 500) {
if ($evalue % 500 == 0) {
return isset($GLOBALS['em_' . $egroup . 's'][$evalue]) ? $GLOBALS['em_' . $egroup . 's'][$evalue] : '';
} else {
if (preg_match('#([0-9]{1,})\\.([0-9]{1,})#', $evalue, $matchs)) {
$esonvalue = $matchs[1];
$etopvalue = $esonvalue - $esonvalue % 500;
$esecvalue = preg_replace('/(?<=\.)[0]+/', '', $evalue);
$GLOBALS['em_' . $egroup . 's'][$etopvalue] = empty($GLOBALS['em_' . $egroup . 's'][$etopvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$etopvalue];
$GLOBALS['em_' . $egroup . 's'][$esonvalue] = empty($GLOBALS['em_' . $egroup . 's'][$esonvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$esonvalue];
$GLOBALS['em_' . $egroup . 's'][$esecvalue] = empty($GLOBALS['em_' . $egroup . 's'][$esecvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$esecvalue];
return $GLOBALS['em_' . $egroup . 's'][$etopvalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$esonvalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$esecvalue];
}
else
{
$elimit = $evalue % 500;
$erevalue = $evalue - $elimit;
$GLOBALS['em_' . $egroup . 's'][$erevalue] = empty($GLOBALS['em_' . $egroup . 's'][$erevalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$erevalue];
$GLOBALS['em_' . $egroup . 's'][$evalue] = empty($GLOBALS['em_' . $egroup . 's'][$evalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$evalue];
return $GLOBALS['em_' . $egroup . 's'][$erevalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$evalue];
}
}
}
}
?>
修改完毕。
需要注意的是:添加新字段时候,表单提示文字必须和联动的组类别名一致,比如我要添加一个表单提示文字是“课程”,那么新增联动类别组的时候类别名也要填写“课程”
1.在\dede\templets\diy_list.htm 找到(大约在41行):
else if($fielddata[1]=='addon')
{
$fields[$field] = "<a href='{$fields[$field]}' target='_blank'><img src='images/channeladd.gif' border='0' /> 其它附件</a>";
}
在下面加入:
//联动类型显示修正开始
else if($fielddata[1]=='stepselect')
{
$db->Execute('me',"SELECT * FROM `dede_stepselect` WHERE egroup='{$field}'");
while($arr = $db->GetArray(me))
{
$egroup = $arr['egroup'];
}
$fields[$field] = Getenums("{$fields[$field]}",$egroup);
}
//联动类型显示修正结束www.80zhan.com织梦模板下载
继续找到:
{/dede:datalist}
在下面加入:
<?php
function Getenums($evalue = 0, $egroup)
{
if (!isset($GLOBALS['em_' . $egroup . 's'])) {
$cachefile = DEDEDATA . '/enums/' . $egroup . '.php';
if (!file_exists($cachefile)) {
require_once DEDEINC . '/enums.func.php';
WriteEnumsCache();
}
if (!file_exists($cachefile)) {
return '';
} else {
require_once $cachefile;
}
}
if ($evalue >= 500) {
if ($evalue % 500 == 0) {
return isset($GLOBALS['em_' . $egroup . 's'][$evalue]) ? $GLOBALS['em_' . $egroup . 's'][$evalue] : '';
} else {
if (preg_match('#([0-9]{1,})\\.([0-9]{1,})#', $evalue, $matchs)) {
$esonvalue = $matchs[1];
$etopvalue = $esonvalue - $esonvalue % 500;
$esecvalue = preg_replace('/(?<=\.)[0]+/', '', $evalue);
$GLOBALS['em_' . $egroup . 's'][$etopvalue] = empty($GLOBALS['em_' . $egroup . 's'][$etopvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$etopvalue];
$GLOBALS['em_' . $egroup . 's'][$esonvalue] = empty($GLOBALS['em_' . $egroup . 's'][$esonvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$esonvalue];
$GLOBALS['em_' . $egroup . 's'][$esecvalue] = empty($GLOBALS['em_' . $egroup . 's'][$esecvalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$esecvalue];
return $GLOBALS['em_' . $egroup . 's'][$etopvalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$esonvalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$esecvalue];
}
else
{
$elimit = $evalue % 500;
$erevalue = $evalue - $elimit;
$GLOBALS['em_' . $egroup . 's'][$erevalue] = empty($GLOBALS['em_' . $egroup . 's'][$erevalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$erevalue];
$GLOBALS['em_' . $egroup . 's'][$evalue] = empty($GLOBALS['em_' . $egroup . 's'][$evalue]) ? '' : $GLOBALS['em_' . $egroup . 's'][$evalue];
return $GLOBALS['em_' . $egroup . 's'][$erevalue] . ' - ' . $GLOBALS['em_' . $egroup . 's'][$evalue];
}
}
}
}
?>
修改完毕。
需要注意的是:添加新字段时候,表单提示文字必须和联动的组类别名一致,比如我要添加一个表单提示文字是“课程”,那么新增联动类别组的时候类别名也要填写“课程”