开发者

Website flow in php

开发者 https://www.devze.com 2023-02-08 21:00 出处:网络
I have a form which allows users to comment on a page, however they are required to login/register before they can post.

I have a form which allows users to comment on a page, however they are required to login/register before they can post.

If they make a mistake (e.g. reply is too short) they are told after they have a logged in ('There was an error with you reply'...).

However then the contents of their reply is lost, how can I save this so that it shows up in the form?

The form page is fairly simple:

<?php if (isset($errors['reply_header'])) echo $errors['reply_header']; ?>

<form method="post" action="http://localhost/LOGIN/user/?action=开发者_JAVA百科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-->

This submits to this page:

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

I know I can save the contents of the form in a session, but where would I put this?


You doing $_GET but your form method is post

So instead of $_GET you should use $_POST

NOTE change your action and make that reply $_GET variable also a

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

Watch if that works


You should save it in a session var before this line (I assume that if user is not logged in this script will not let the rest of the code execute).

require_once FORUM_ROOT . 'register/index.php';


Assuming that the comment is entered to a textarea, you could do this:

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

Of course, you'll need to replace $_POST['text'] with the actual name of the textarea.

0

精彩评论

暂无评论...
验证码 换一张
取 消