【发布时间】:2011-03-04 05:57:00
【问题描述】:
我正在为我提交的 HTML 表单设置一个带有成功消息的 PHP 会话变量。如果没有表单错误,我会重定向到同一页面(使用 header())并显示来自会话变量的消息。直到这里一切都很好,但是如果我在提交后再次访问该页面,消息仍然存在。是不是只能在我提交成功后重定向时才出现?
我的 form.php 代码如下所示:
if (isset($_POST['submit'])) {
// some form processing here
if (count($errors) == 0) {
// some data saving here
$_SESSION['status'] = 'Thank you for submitting the form';
header('Location: /form.php');
}
现在是我的模板文件:
{if isset($smarty.session.status)}
<p><strong>{$smarty.session.status)</strong></p>
{/if}
<!-- form html code goes here -->
谢谢。
【问题讨论】: