我知道会话。 想问一下是否有更多方法可以在页面中保存变量并在表单之间共享它们。示例代码不起作用,因为我不知道如何在不使用会话的页面中共享 varf1、varf2、varf3:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
</head>
<body>
<!-- Question: how to access variables varf1, varf2, varf3 in all three forms? -->
<!-- <?php $varf1= $_POST['varf1']; $varf2= $_POST['varf2']; $varf3= $_POST['varf3']; $_POST['fsn1']=""; $_POST['fsn2']=""; ?> -->
<?php $varf1=$_POST['varf1']=$varf2=$_POST['varf2']=$varf3=$_POST['varf3']=""; ?>
<!-- form1 generates form2, and form 2 generates form3 -->
<form name="form1" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
<?php $varf1="varf1";
echo "in form1, var1=".$varf1.", var2=".$varf2.", var3=".$varf3; ?>
<input type="submit" id="fsi1" value="fsv1" name="fsn1"> <br>
</form>
<?php if($_SERVER["REQUEST_METHOD"] == "POST") {
if(!empty($_POST['fsn1'])) { ?>
<form name="form2" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
<?php $varf2="varff2";
echo "in form2, var1=".$varf1.", var2=".$varf2.", var3=".$varf3; ?>
<input type="submit" id="fsi2" value="fsv2" name="fsn2">
</form><br>;
<?php } // if(!empty($_POST['fsn1'])
if(!empty($_POST['fsn2'])) { ?>
<form name="form3" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> ">
<?php $varf3="varff3";
echo "in form3, var1=".$varf1.", var2=".$varf2.", var3=".$varf3; ?>
<input type="submit" id="fsi3" value="fsv3" name="fsn3">
</form><br>;
<?php } // if(!empty($_POST['fsn2']))
} // if($_SERVER["REQUEST_METHOD"
?>
</body>
</html>
您可以随时使用
<input type="hidden" name="varf1" value="<?php echo $varf1?>">
在每种形式中。