ecshop留言板里添加1项必填项表单

ECSHOP教程 来源: ECSHOP教程网www.ecshop119.com 时间:2012-02-16 ECSHOP教程分类:其他ECSHOP教程

ecshop留言板添加一项必填项-联系人 一、首先要为你的数据库的ecs_comment增加一个字段以存储联系人姓名: 可以直接在后台--数据库管理---SQL查询里里直接执行以下sql语句: alter table feedback add contact varchar(60) not null default ''; 此处注意,这条sql语句中的表前缀ecs_要和你网站的前缀一致,不然会报错,如果你不知道你ecshop网站的数据表前缀 ,请看这里 二、修改评论提交表单ecshop留言板添加一项必填项-联系人

 


一、首先要为你的数据库的ecs_comment增加一个字段以存储联系人姓名:
可以直接在后台-->数据库管理--->SQL查询里里直接执行以下sql语句:
alter table feedback add contact varchar(60) not null default '';
此处注意,这条sql语句中的表前缀ecs_要和你网站的前缀一致,不然会报错,如果你不知道你ecshop网站的数据表前缀
,请看这里

二、修改评论提交表单增加联系人表单项
打开你网站的themes文件夹,找到你的模板风格,进入里面,找到message_board.dwt,在
<tr>
<td align="right">{$lang.email}</td>
<td><input name="user_email" type="text" class="inputBg" size="20" value="{$smarty.session.email|escape}" /></td>
</tr>
这段代码的下方增加

<tr>
<td align="right">联系人</td>
<td><input name="contact" type="text" class="inputBg" size="20" value="" /></td>
</tr>
然后修改提交评论的js函数为
/**
* 提交留言信息
*/
function submitMsgBoard(frm)
{
var msg = new Object;

msg.user_email = frm.elements['user_email'].value;
msg.contact = frm.elements['contact'].value;
msg.msg_title = frm.elements['msg_title'].value;
msg.msg_content = frm.elements['msg_content'].value;
msg.captcha = frm.elements['captcha'] ? frm.elements['captcha'].value : '';

var msg_err = '';

if (msg.user_email.length > 0)
{
if (!(Utils.isEmail(msg.user_email)))
{
msg_err += msg_error_email + '\n';
}
}
else
{
msg_err += msg_empty_email + '\n';
}
if (msg.contact.length == 0)
{
msg_err += '联系人不能为空\n';
}
if (msg.msg_title.length == 0)
{
msg_err += msg_title_empty + '\n';
}
if (frm.elements['captcha'] && msg.captcha.length==0)
{
msg_err += msg_captcha_empty + '\n'
}
if (msg.msg_content.length == 0)
{
msg_err += msg_content_empty + '\n'
}
if (msg.msg_title.length > 200)
{
msg_err += msg_title_limit + '\n';
}

if (msg_err.length > 0)
{
alert(msg_err);
return false;
}
else
{
return true;
}
}

广州斑马工作室,专业为你设计ECSHOP模板,shopex模板。www.banma.cc
 

三、修改处理评论提交的message.php
if ($action == 'act_add_message')
{
include_once(ROOT_PATH . 'includes/lib_clips.php');

/* 验证码防止灌水刷屏 */
if ((intval($_CFG['captcha']) & CAPTCHA_MESSAGE) && gd_version() > 0)
{
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha']);
}
}
else
{
/* 没有验证码时,用时间来限制机器人发帖或恶意发评论 */
if (!isset($_SESSION['send_time']))
{
$_SESSION['send_time'] = 0;
}

$cur_time = gmtime();
if (($cur_time - $_SESSION['send_time']) < 30) // 小于30秒禁止发评论
{
show_message($_LANG['cmt_spam_warning']);
}
}
$user_name = '';
if (empty($_POST['anonymous']) && !empty($_SESSION['user_name']))
{
$user_name = $_SESSION['user_name'];
}
elseif (!empty($_POST['anonymous']) && !isset($_POST['user_name']))
{
$user_name = $_LANG['anonymous'];
}
elseif (empty($_POST['user_name']))
{
$user_name = $_LANG['anonymous'];
}
else
{
$user_name = htmlspecialchars(trim($_POST['user_name']));
}

$user_id = !empty($_SESSION['user_id']) ? $_SESSION['user_id'] : 0;
$message = array(
'user_id' => $user_id,
'user_name' => $user_name,
'user_email' => isset($_POST['user_email']) ? htmlspecialchars(trim($_POST['user_email'])) : '',
'contact' => isset($_POST['user_email']) ? htmlspecialchars(trim($_POST['contact'])) : '',

'msg_type' => isset($_POST['msg_type']) ? intval($_POST['msg_type']) : 0,
'msg_title' => isset($_POST['msg_title']) ? trim($_POST['msg_title']) : '',
'msg_content' => isset($_POST['msg_content']) ? trim($_POST['msg_content']) : '',
'order_id' => 0,
'msg_area' => 1,
'upload' => array()
);

if (add_message($message))
{
if (intval($_CFG['captcha']) & CAPTCHA_MESSAGE)
{
unset($_SESSION[$validator->session_word]);
}
else
{
$_SESSION['send_time'] = $cur_time;
}
$msg_info = $_CFG['message_check'] ? $_LANG['message_submit_wait'] : $_LANG['message_submit_done'];
show_message($msg_info, $_LANG['message_list_lnk'], 'message.php');
}
else
{
$err->show($_LANG['message_list_lnk'], 'message.php');
}
}

四、增加后台显示联系人

a、打开admin/user_msg.php,把
/**
*
*
* @access public
* @param
*
* @return void
*/
function msg_list()
{
/* 过滤条件 */
$filter['keywords'] = empty($_REQUEST['keywords']) ? '' : trim($_REQUEST['keywords']);
if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1)
{
$filter['keywords'] = json_str_iconv($filter['keywords']);
}
$filter['msg_type'] = isset($_REQUEST['msg_type']) ? intval($_REQUEST['msg_type']) : -1;
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'f.msg_id' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);

$where = '';
if ($filter['keywords'])
{
$where .= " AND f.msg_title LIKE '%" . mysql_like_quote($filter['keywords']) . "%' ";
}
if ($filter['msg_type'] != -1)
{
$where .= " AND f.msg_type = '$filter[msg_type]' ";
}

$sql = "SELECT count(*) FROM " .$GLOBALS['ecs']->table('feedback'). " AS f" .
" WHERE parent_id = '0' " . $where;
$filter['record_count'] = $GLOBALS['db']->getOne($sql);

/* 分页大小 */
$filter = page_and_size($filter);

$sql = "SELECT f.msg_id, f.user_name, f.contact, f.msg_title, f.msg_type, f.order_id, f.msg_status, f.msg_time, f.msg_area, COUNT(r.msg_id) AS reply " .
"FROM " . $GLOBALS['ecs']->table('feedback') . " AS f ".
"LEFT JOIN " . $GLOBALS['ecs']->table('feedback') . " AS r ON r.parent_id=f.msg_id ".
"WHERE f.parent_id = 0 $where " .
"GROUP BY f.msg_id ".
"ORDER by $filter[sort_by] $filter[sort_order] ".
"LIMIT " . $filter['start'] . ', ' . $filter['page_size'];

$msg_list = $GLOBALS['db']->getAll($sql);
foreach ($msg_list AS $key => $value)
{ if($value['order_id'] > 0)
{
$msg_list[$key]['order_sn'] = $GLOBALS['db']->getOne("SELECT order_sn FROM " . $GLOBALS['ecs']->table('order_info') ." WHERE order_id= " .$value['order_id']);
}
$msg_list[$key]['msg_time'] = local_date($GLOBALS['_CFG']['time_format'], $value['msg_time']);
$msg_list[$key]['msg_type'] = $GLOBALS['_LANG']['type'][$value['msg_type']];
}
$filter['keywords'] = stripslashes($filter['keywords']);
$arr = array('msg_list' => $msg_list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);

return $arr;
}

b、打开admin/templates/msg_list.htm 把
<td align="center">{$msg.user_name}</td>
改成
<td align="center">{$msg.user_name}<br />{$msg.contact}</td>

这样就实现了这个功能

 

本文模板屋原创地址: https://www.ecshop119.com/ecshopjc-361.html
模板屋版权所有 © 转载时必须以链接形式注明出处!

ECSHOP模板屋
ecshop开发团队 ecshop开发中心 ecshop模板制作 ecshop模板屋
ECSHOP
ecshop下载 ecshop安装教程 ecshop在线演示 ecshop后台测试
ECSHOP二次开发手册
ecshop教程 ecshop二次开发 ecshop模板教程 ecshop微信配置
ECSHOP商城网站建设
ecshop空间域名 ecshop商城建设 ecshop模板修改 ecshop开发定制
服务支持:7X24小时 151 059 55077
ECShop二次开发
ecshop搭建
qqtelcodeback_top
温馨提示

确定取消
温馨提示

关闭