我已经在多表单页面上工作了一段时间。我需要一些帮助来尝试理解为什么当我取消设置变量时,多表单页面无法正常工作。我在代码中放置了一条 echo 语句来跟踪变量值,甚至在页面刷新后变量仍然保留。从字面上看,我必须删除该站点的 cookie 才能取消设置该变量。
这是代码:
<?php
session_start();
// Start the session
echo $_SESSION["formatPickleball"];
$_SESSION["Pickleball"] = "";
// Submit button is pressed
if (isset($_POST['format1']))
{
$_SESSION["formatPickleball"] = $_POST['member'];
$_SESSION["Pickleball"] = "hide";
}
if ($_SESSION["formatPickleball"] == "Captain") {
$regCAP = "";
// Submit button is pressed
if (isset($_POST['submitCAP']))
{
$regCAP = "show";
}
$secondCAP = "";
// Submit button is pressed
if (isset($_POST['submit2']))
{
$secondCAP = "show";
}
$thirdCAP = "";
// Submit button is pressed
if (isset($_POST['submit3']))
{
$thirdCAP = "show";
}
} elseif ($_SESSION["formatPickleball"] == "Player") {
$regPlay = "";
// Submit button is pressed
if (isset($_POST['submitPlay']))
{
$regPlay = "show";
}
}
?>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.min.css">
<script type="text/javascript"></script>
<body>
<div id="mainForm">
<h4>Are you a Captain or a Player on a Team?</h4>
<form method='POST'>
<input type="radio" name="member" value="Captain">Captain
<input type="radio" name="member" value="Player">Player<br>
<input type="submit" name="format1" value="Select">
</form>
</div>
当我添加 $_SESSION["formatPickleball"] = ""; 到php代码的顶部,多表单无法正常工作。
我有两个问题 1) 如何在不删除 cookie 的情况下取消设置变量?2)这是用 PHP 编写此代码的最有效方法吗?
千万里不及你
不负相思意
素胚勾勒不出你
相关分类