加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php表单 – 2个按钮(一个用于销毁会话和重新加载页面,另一个用于

发布时间:2020-12-13 16:11:33 所属栏目:PHP教程 来源:网络整理
导读:在’selecteditems.php’页面上,我有一个这样的表格: form method="POST" name="selecteditems" action="nextpage.php"....i have some code here to display the values of the SESSION array in a table....input type="button" name="clear" value="Clea
在’selecteditems.php’页面上,我有一个这样的表格:

<form method="POST" name="selecteditems" action="nextpage.php">
....i have some code here to display the values of the SESSION array in a table....
<input type="button" name="clear" value="Clear Session" onclick="window.location='selecteditems.php'">
<input type="submit" name="next" value="Go to Checkout">
</form>

在’selecteditems.php’页面上的表单之前,我有一些代码将数据($_REQUEST params从名为’selecteditems.php’的页面)添加到$_SESSION数组(这很好).
在表单中我有一些代码来显示$_SESSION数组中的所有内容(这很好).如果会话为空,则应打印“session is empty”.

我的问题:
我希望能够点击“清除会话”按钮并销毁会话以及重新加载“selecteditems.php”页面以说“会话为空”.如果单击“转到结帐”按钮,我想简单地发送到nextpage.php页面.

在删除会话后,获取“selecteditems.php”以重新加载并回显“session is empty”,我们将不胜感激.

解决方法

只需将您的清除会话按钮设置为提交按钮,类型为“提交”(您将其设置为type =“button”,其中跨浏览器的行为不一致无效)然后您可以将其视为正常提交流程:

if(isset($_POST['clear'])) {
    session_destroy(); // Or other session-unsetting logic
    header("Location: selecteditems.php"); // Reload your page
}

if(isset($_POST['next'])) {
    //next page logic
}

您甚至可能不需要重新加载明确的会话页面.对于’会话清除消息’,您可以将逻辑添加到$_POST [‘clear’]块,或重定向到’selecteditems.php?msg =已清除’并搜索$_GET [‘msg’]并输出正确的信息,由你决定:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读