开发者

Keep input values after post

I have a website that uses seperate files to process the PHP like the post form is on one page and when a user submits the form, it goes to contact_form.php then when the PHP has processed the form, it will redirect the user with this part of the code:

// rest of code above

if($result)
{
    $_SESSION['SUCCESS'] = "Your message was posted";
    header("Location: viewtopic.php?id=" . $id . "&mode=view");
}
else
{
    $_SESSION['ERROR'] = "Your message could not be posted";
    header("Location: viewtopic.php?id=" . $id . "&mode=add");
}

Since the else part would return to the posting page and the values that were submitted would be empty in the input fields, I need them intact when an error has returned...

I wouldn't r开发者_如何学Cely on JavaScript validation since users may have them disabled, so I have no idea would be the best method for me to use when returning with errors and the values are intact in the input fields.


You can put those post values in session variables as well and fill the form again in case of error. May be something like this:

$_SESSION['POST'] = $_POST;


You would normally post the form back to the same URL and do the processing on the same page. You only redirect on success. If there is an error you carry on rendering the form, populating the fields with the values posted back.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜