我在不同页面上有一系列表单,并希望在所有页面上临时存储值,并在填写完所有表单后将其邮寄。
显然$ _SESSION是最好的方法???这就是我得到的:
的index.php
<!DOCTYPE html>
<html>
<head>
<title>Whats your name?</title>
</head>
<body>
<form action="two.php" method="post">
Fav color:<br>
<input name="color" type="text" value="blue"><br>
Fav sport:<br>
<input name="sport" type="text" value="soccer"><br>
<br>
<input type="submit" value="Next">
</form>
</body>
</html>
two.php
<!DOCTYPE html>
<html>
<head>
<title>Where do you live?</title>
</head>
<body>
<form action="post.php" method="post">
Shoe size:<br>
<input name="size" type="text" value="4"><br>
left or right handed?:<br>
<input name="hand" type="text" value="left"><br>
<br>
<input type="submit" value="Next">
</form>
</body>
</html>
post.php中
<?php
$to = "myemail@host.com";
$sub = "Testing session out";
mail($to, $sub, $message);
header('Location: finish.php');
?>
finish.php
<!DOCTYPE html>
<html>
<head>
<title>Thanks</title>
<meta http-equiv="refresh" content="2; URL='http://new-website.com' " />
</head>
<body>
<p>All done, thanks</p>
</body>
</html>
我想&#34; post.php&#34;将所有值一次性邮寄到我的电子邮件中,例如
$message = $_POST['color'];
$message .= $_POST['sport'];
$message .= $_POST['size'];
$message .= $_POST['hand'];
答案 0 :(得分:1)
只需将$_POST
添加到$_SESSION
<?php
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
?>
但是在“post.php”中,你不能用post,
来调用firstname和lastname$message = $_SESSION['firstname'];
$message .= $_SESSION['lastname'];
$message .= $_POST['door'];
$message .= $_POST['zip'];
不要忘记在开始脚本中使用session_start
或者您可以再次添加标记input
,而不是$_SESSION
格式
<input name="firstname" type="hidden" value="<?php echo $_POST['firstname']; ?>" />
<input name="lastname" type="hidden" value="<?php echo $_POST['lastname']; ?>" />