我有一个表单,允许用户在页面上发表评论,但他们需要登录/注册才能张贴。
如果他们犯了一个错误(例如回复太短),他们会在登录后被告知(“你回复时出错”...)。
然而,他们回复的内容丢失了,我如何保存它才能显示在表单中?
表单页面相当简单:
<?php if (isset($errors['reply_header'])) echo $errors['reply_header']; ?>
<form method="post" action="http://localhost/LOGIN/user/?action=reply">
<input type="hidden" name="auth_token" value="<?php echo $auth_token; ?>">
<input type="hidden" name="thread_id" value="<?php echo $id; ?>">
<!--rest of the form goes here, thread_id shows us which thread/page they are replying to-->这将提交到此页面:
# get the register/login controller:
require_once FORUM_ROOT . 'register/index.php'; // if session is not set, then ask for login
if (isset($_GET['action']) )
{
switch ($_GET['action'])
{
case 'new': # create a new thread...
require_once USER_ROOT . 'new_thread.php';
break;
case 'reply':
$_POST['action'] == 'Reply';
require_once USER_ROOT . 'thread_reply.php';
die();
break;
default: # show user page...
require_once USER_ROOT . 'main.html.php';
break;
}
}我知道我可以在会话中保存表单的内容,但是我应该把它放在哪里呢?
发布于 2011-02-05 05:20:34
您正在执行$_GET,但表单方法是post
因此您应该使用$_POST而不是$_GET
注意,更改您操作,并使回复$_GET变量也成为
<input type="hidden" name="action" value="reply" />看看这是否起作用
发布于 2011-02-05 05:23:05
您应该在该行之前将其保存在会话变量中(我假设如果用户没有登录,该脚本将不会让其余代码执行)。
require_once FORUM_ROOT . 'register/index.php';https://stackoverflow.com/questions/4903058
复制相似问题