请教编程思路!
本人刚学php,要编写一个文章发布的页面,有一组单选钮(A、B两个),一个单行文本输入和一个多行文本输入。
当选A时(默认),页面与这里的提问页面大致相同,当选B时,将在原有页面基础上增加新的内容,比如一行文本。
我在单选钮上编了一个js的onclick的响应函数,这个函数把单选钮的选项,单行文本的值和多行文本的值记录到cookie中,然后刷新。
在php页面中用if判断一下cookie中的值,以便在刷新后还能保持不变。
以上内容已实现,但当多行文本内容太多时,cookie存不下,当刷新后多行文本内容出错。
我打算用数据库实现多行文本的暂时记录,但这又影响速度,不知道各位是否遇到过这样的问题,请告知是如何实现的。
源代码如下,请各位高手指教,谢谢:)
-----------------------------------
<?php
if(!isset($userselect))
setcookie("userselect","1");
if(!isset($uflag))
setcookie("uflog","0");
?>
<html>
<script language="javascript">
<!--
function openwin() {
wins=open('overloadimage.php','WINTS','toolbar=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=420');
}
function refresh(number){
var days = 1;
var expdate = new Date();
expdate.setTime (expdate.getTime() + 1000 );
document.cookie = "userselect =" + number + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "usertitle =" + document.F1.T1.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userclass =" + document.F1.D1.selectedIndex + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "usertext =" + document.F1.S1.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userrelation =" + document.F1.T2.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userquote =" + document.F1.T3.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "userauthor =" + document.F1.T4.value + "; expires=" + expdate.toGMTString() + ";";
document.cookie = "uflag = 1 ; expires=" + expdate.toGMTString() + ";";
window.location.reload();
}
//-->
</script>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新闻模板--增加新闻</title>
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<body>
<form method="POST" action="post.php" name="F1">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="305">
<tr>
<td width="100%" colspan="2" bgcolor="#A6CA27" height="24">
<p align="center"><b><font size="2" color=#ffffff>增 加 新 闻</font></b></td>
</tr> <tr>
<td width="15%" align="right" height="24" valign="top">文章类型(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24">
<?php
include("newstype.php");
?>
<font color="#CC0033"> 请先选择此项,否则更新页面时将清除其它输入的内容!</font>
</td>
</tr>
<tr>
<td width="15%" align="right" height="30">文章标题(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="30">
<?php
if($_COOKIE['uflag']==0)
echo ' <input type="text" name="T1" size="50" style="background-color:ffffff;color:000000;border: 1 double" maxlength="120">';
else{
echo ' <input type="text" name="T1" size="50" value="'.$_COOKIE['usertitle'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="120">';
}
?>
<font color=#CC0033> 标题请不要超过60个汉字!</font> </td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">文章分类(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24">
<select size="1" name="D1">
<?php
include("newsclass.php");
?>
</select>
</td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">文章内容(<font color="#FF0000">*</font>):</td>
<td width="85%" valign="middle" height="24">
<?php
if($_COOKIE['uflag']==0)
echo '<textarea rows="23" name="S1" cols="77"></textarea>';
else
echo '<textarea rows="23" name="S1" cols="77">'.$_COOKIE['usertext'].'</textarea>';
?>
</td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top"> </td>
<td width="85%" valign="middle" height="24"><font color="#CC0033"> 本系统支
持多种格式修饰功能,请参阅<a href="formathelp.htm">帮助</a>。</font></td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">相关新闻:</td>
<td width="85%" valign="middle" height="24">
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T2" size="50" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
else
echo '<input type="text" name="T2" size="50" value="'.$_COOKIE['userrelation'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
?>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top"> </td>
<td width="85%" valign="middle" height="24"><font color="#CC0033"> 相关新闻只需输入关键字或完整标题,关键字之间请用西文状态下的分号(;)分开,总长不得超过25个汉字</font></td>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">来源:</td>
<td width="85%" valign="middle" height="24">
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T3" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
else
echo '<input type="text" name="T3" size="16" value="'.$_COOKIE['userquote'].'" style="background-color:ffffff;color:000000;border: 1 double" maxlength="50"></td>';
?>
</tr>
<tr>
<td width="15%" align="right" height="24" valign="top">文章作者:</td>
<td width="85%" valign="middle" height="24">
<?php
if($_COOKIE['uflag']==0)
echo '<input type="text" name="T4" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="12">';
else
echo '<input type="text" name="T4" value="'.$_COOKIE['userauthor'].'" size="16" style="background-color:ffffff;color:000000;border: 1 double" maxlength="12">';
?>
</td>
</tr>
<?php
if ($_COOKIE['userselect']==2){
echo "<tr>";
echo '<td width="100%" align="center" height="24" valign="top" colspan="2"> <input type="button" value="上传本地图片..." name="B3" class="mface" OnClick=openwin()></td>';
echo "</tr>";
echo "<tr>";
echo '<td width="100%" align="center" height="24" colspan="2">';
echo '<font color="#CC0033">上传本地图片是使用了[img]n[/img](其中n为1、2...)方式时所必须使用的,使用[img]http://...[/img]方式时不用使用此项</font></td>';
echo "</tr>";
}
?>
<tr>
<td width="100%" align="center" height="24" colspan="2">
<font color="#CC0033">代(*)的项目必须有内容<br>新闻增加后还不能立即发表,需等待审核后,才可在新闻中心看到,如出现发布问题请与审核员联系</font></td>
</tr>
<tr>
<td width="100%" align="center" height="24" colspan="2">
<input type="submit" value=" 提 交 "
name="cmdok" class="mface">
<input type="reset" value=" 清 除 "
name="cmdcancel" class="mface">
<p><font color="#CC0033">如有技术问题,请与管理员联系</font></td>
</tr>
</table>
</form>
</body>
</html>