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. I would really appreciate some help.
Solution 1:
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.
Try the following and see if it works.
First Form (form2.php
)
<html><head><title>FORM</title></head><body><formaction="form3.php"method="POST">
Name:<inputtype="text"name="name" />
Address:<inputtype="text"name="address" /><inputtype="submit"name="submit"value="submit" /></form></body></html>
Second Form (form3.php
)
<html><head><title>MY HOMEPAGE</title></head><body><?phpif(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
.- Added
isset
to check if thePOST
data is being received in theform3.php
file.- Added
isset
to all the variables (name
andaddress
in this case) to check if they are being received.
Solution 2:
It seems you are using linux environment, the form action (form3.php
) and file name (Form3.php
) are not same. In linux environment these are case sensitive. Please make action uri & file name in same case.
Post a Comment for "How To Pass The Value Of A Form To Another Form?"