[英]How to pass the value of a form to another form?
I have a task in which I need to pass the value of a form in a page to another one. 我有一项任务,需要将页面中表单的值传递给另一个表单。 I am using
POST
method to do this, but it is not working. 我正在使用
POST
方法来执行此操作,但是它不起作用。 I would really appreciate some help. 我真的很感谢您的帮助。
This is the code I am using: 这是我正在使用的代码:
First Form ( form2.php
) 第一种形式 (
form2.php
)
<html>
<head>
<title>FORM</title>
</head>
<body>
<form action="form3.php" method="post">
Name:<input type="text" name="name">
Address:<input type="text" name="address">
<input type="submit" name="Submit" value="submit">
</form>
</body>
</html>
Second Form ( form3.php
) 第二形式 (
form3.php
)
<html>
<head>
<title>MY HOMEPAGE</title>
</head>
<body>
<?php
$x=$_POST['name'];
$y=$_POST['address'];
echo $x;
echo $y;
?>
</body>
</html>
At first glance, your code seems just fine. 乍一看,您的代码看起来还不错。 There are a few minor things you have missed, though none of them should normally prevent you from getting the output.
您虽然错过了一些小事情,但通常都不会阻止您获得输出。 But just to be sure, I have tidied up the code and added a test for each
POST
variable. 但是可以肯定的是,我整理了代码并为每个
POST
变量添加了一个测试。
Try the following and see if it works. 请尝试以下操作,看看是否可行。
First Form ( form2.php
) 第一种形式 (
form2.php
)
<html>
<head>
<title>FORM</title>
</head>
<body>
<form action="form3.php" method="POST">
Name:<input type="text" name="name" />
Address:<input type="text" name="address" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Second Form ( form3.php
) 第二形式 (
form3.php
)
<html>
<head>
<title>MY HOMEPAGE</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
if(isset($_POST['name']))
{
$x=$_POST['name'];
}
if(isset($_POST['address']))
{
$y=$_POST['address'];
}
}
echo $x;
echo $y;
?>
</body>
</html>
This is what I added to your code:
这是我添加到您的代码中的内容:
- Closed the open
input
tags inform2.php
.关闭了
form2.php
打开的input
标签。- Added
isset
to check if thePOST
data is being received in theform3.php
file.添加了
isset
以检查是否在form3.php
文件中接收到POST
数据。- Added
isset
to all the variables (name
andaddress
in this case) to check if they are being received.将
isset
添加到所有变量(在这种情况下为name
和address
),以检查是否已接收它们。
It seems you are using linux environment, the form action ( form3.php
) and file name ( Form3.php
) are not same. 看来您使用的是Linux环境,表单操作(
form3.php
)和文件名( Form3.php
)不相同。 In linux environment these are case sensitive . 在linux环境中,它们区分大小写 。 Please make action uri & file name in same case.
请在相同情况下设置操作uri和文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.