0

我有一个允许用户在页面上发表评论的表单,但是他们需要登录/注册才能发布。

如果他们犯了错误(例如回复太短),他们会在登录后被告知('There was an error with you reply'...)。

但是,他们回复的内容丢失了,我该如何保存它以使其显示在表单中?

表单页面相当简单:

<?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;
    }    
}

我知道我可以在会话中保存表单的内容,但我应该把它放在哪里?

4

3 回答 3

2

你在做$_GET ,但你的表单方法是 post

所以$_GET你应该使用$_POST

注意更改您的操作并使回复 $_GET 变量也成为

<input type="hidden" name="action" value="reply" />

看看这是否有效

于 2011-02-04T21:20:33.640 回答
0

您应该将它保存在此行之前的会话变量中(我假设如果用户未登录此脚本将不会让其余代码执行)。

require_once FORUM_ROOT . 'register/index.php';
于 2011-02-04T21:23:05.053 回答
0

假设评论输入到文本区域,您可以这样做:

<文本区域>
<?php echo htmlspecialchars ( $_POST['text'] ); ?>
</textarea>

当然,您需要将 $_POST['text'] 替换为文本区域的实际名称。

于 2011-02-04T21:25:15.223 回答