第一个文件,testform 1:
<html>
<head>
<meta charset="UTF-8">
<title>testform 1</title>
</head>
<body>
<form action="test.php" method="post" name="testform1">
<label for="naam">naam:</label>
<input type="text" name="naam"><br>
<input type="hidden" name="action" value="form1">
<input type="submit" value="form1">
</form>
</body>
</html>
第二个文件,testform 2:
<html>
<head>
<meta charset="UTF-8">
<title>testform 1</title>
</head>
<body>
<form action="test.php" method="post" name="testform2">
<label for="achternaam">achternaam:</label>
<input type="text" name="achternaam"><br>
<input type="hidden" name="action" value="form2">
<input type="submit" value="form2">
</form>
</body>
</html>
test.php文件:
<?php
$firstname = "";
$lastname = "";
switch($_POST['action']) {
case 'form1':
$firstname = $_POST['naam'];
echo "form 1 gelukt";
header("Location: http://localhost:8081/greenjoy/testform2.html");
break;
case 'form2':
$lastname = $_POST['achternaam'];
echo "form 2 gelukt";
echo "$firstname" . "$lastname";
break;
}
?>
我有这三段代码,它们应该是两种不同的形式,将数据发送到php。但是当我完成填写第二种形式时,第一种形式的数据就消失了。我不能使用2个不同的php文件,因为我必须使用file_get_contents将数据发送到planyo
答案 0 :(得分:-2)
像这样修改你的文件:
testform1.html:没有变化。
testform2.html,将其更改为php文件(testform2.phtml):
<html>
<head>
<meta charset="UTF-8">
<title>testform 1</title>
</head>
<body>
<form action="test.php" method="post" name="testform2">
<label for="achternaam">achternaam:</label>
<input type="text" name="achternaam"><br>
<input type="hidden" name="action" value="form2">
<input type="hidden" name="naam" value="<?php echo $_GET['firstname']; ?>">
<input type="submit" value="form2">
</form>
</body>
</html>
test.php的:
<?php
$firstname = "";
$lastname = "";
switch($_POST['action']) {
case 'form1':
$firstname = $_POST['naam'];
echo "form 1 gelukt";
header("Location: http://localhost:8081/greenjoy/testform2.html?firstname=$firstname");
break;
case 'form2':
$firstname = $_POST['naam'];
$lastname = $_POST['achternaam'];
echo "form 2 gelukt";
echo "$firstname" . "$lastname";
break;
}
?>