您的位置:首页 > 其它

动态增加表单方法--ff/ie

2010-12-21 10:56 78 查看
---------------------增加方法----------------------------
<h3><center>批量增加评论</center></h3><BR>
<form action="" method="post" onsubmit="return check_form();">
<input type="button" value="增加一组评论输入栏" onclick="insert_input();"/>
<input type="submit" value="保存"/>
<BR>
<BR>

<div id=input_div></div>
<BR>
<BR>

<input type="button" value="增加一组评论输入栏" onclick="insert_input();"/>
<input type="submit" value="保存"/>
</form>

<script>
function check_form()
{
if (objs('author[]').length < 1 )
{
alert('未有评论内容,不必提交');
return false;
}

for (var for_i = 0; for_i < objs('author[]').length; for_i++)
{
if (/^ *$/.test(objs('author[]')[for_i].value) )
{
alert('第' + (for_i + 1 ) + '组评论用户未填写');
objs('author[]')[for_i].focus();
return false;
}
if (!/^[1-9]/d*$/.test(objs('agree[]')[for_i].value) )
{
alert('第' + (for_i + 1 ) + '组评论支持人数未填写(必须是数字)');
objs('agree[]')[for_i].focus();
return false;
}
if (/^ *$/.test(objs('title[]')[for_i].value) )
{
alert('第' + (for_i + 1 ) + '组评论标题未填写');
objs('title[]')[for_i].focus();
return false;
}
if (/^ *$/.test(objs('content[]')[for_i].value) )
{
alert('第' + (for_i + 1 ) + '组评论内容未填写');
objs('content[]')[for_i].focus();
return false;
}
if (/^ *$/.test(objs('back[]')[for_i].value) )
{
alert('第' + (for_i + 1 ) + '组评论回复未填写');
objs('back[]')[for_i].focus();
return false;
}
}

return true;
}

function obj(the_id)
{
return document.getElementById(the_id);
}

function objs(the_id)
{
return document.getElementsByName(the_id);
}

function insert_input()
{
if (!window.comment_l) window.comment_l =1;

var obj_h = document.createElement("div");
obj_h.innerHTML = '第' + window.comment_l + '组评论栏<BR><BR>名字:<input id="author[]" name="author[]" style="width:100px;"> ' +
'支持人数:<input id="agree[]" name="agree[]" ><BR>' +
'标题:<input id="title[]" name="title[]" style="width:500px;"><BR>' +
'评论:<textarea id="content[]" name="content[]" style="width:500px;height:50px;"></textarea><BR>' +
'回复:<textarea id="back[]" name="back[]" style="width:500px;height:50px;"></textarea><BR><BR>';
obj('input_div').appendChild(obj_h);
window.comment_l++;

}
</script>

---------------------增加方法--------------

------------------数据库保存方法------------------

if( isset($_POST['content']) )
{
$pid = $_GET['pid'];
$for_i = 0;
$sql_values = '';
$strtest="/select|update|delete|insert/i";

do
{
$sql_values .= ($for_i == 0?'(':',(');//不是第一组时,增加隔开符
$sql_values .= "'". preg_replace($strtest,"",htmlspecialchars($_REQUEST['author'][$for_i])) ."'";//名称
$sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['title'][$for_i])) ."'";//标题
$sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['content'][$for_i])) ."'";//内容
$sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['back'][$for_i])) ."'";//回复
$sql_values .= ", '". preg_replace($strtest,"",htmlspecialchars($_REQUEST['agree'][$for_i])) ."'";//支持
$sql_values .= ",'$pid','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."','".$_SERVER['REMOTE_ADDR']."','1')";//商品,时间,发表时间,ip,启用
$for_i++;
}while ($for_i < count($_POST['content']));

$insert = "insert into ".TABLE.REVIEWS."(`author`,`title`,`content`,`back`,`agree`,`p_id`,`time`,`stime`,`ip`,`enable`) values $sql_values ";
//echo $insert;
$result=$db->query($insert);

if($result)
{
$say = '评论发送成功!';
$search = '?pid='.$pid.'&show_create=1';
}
else
{
$say = '评论发送失败!';
$search = '?pid='.$pid;
}

echo "<script>alert('$say');window.location.href='".$php_url."/bsh_syadmin/comment_by_us.php$search';</script>";
}

-------------------------------数据库保存方法------------------

这是为一个商场管理后台增加功能;



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: