Hi friends,
I have a multi form(actually is one whole form, but split into multiple forms).
From the image seen
When i typed the name data in Form 1, and click the next button and go to Form 2...
In Form 2 when i typed the Email data..and then i realize, the name data that i entered in Form 1, is wrong, so, I click the <Back button in Form 2..and i go in but i dont see the data that i typed in, then when i click the next button in Form1 to go to Form 2> I cant see the data thats been typed in Form 2 also..
I can insert the data into table, If i just go forward.... >>
ie:
Form1 -> Form 2 -> Result.
How can this problem be solved?
I want to see the data's that been typed in, either if they go <back or Forward>..
Can some1 guide me with this..


Thanks,
Tryphy

Could you not use a $_SESSION and pass a session to each page? once the form is complete you can kill the session.

Might not be the best solution

Hope it helps...

Could you not use a $_SESSION and pass a session to each page? once the form is complete you can kill the session.

Might not be the best solution

Hope it helps...

Yah, i used session to pass the values from one page to another,
But when, click back button, how does the value appear in the textbox..
I am so confused..

Can explain me ?

you can make it in a simpler way if you are having only one field.
Form1.php

<?php
$formdata = "<form name='form1' action='form2.php' method='post' >";
$formdata .= "<input type='hidden' name='email' value='".$email."' />";
$formdata .= "<input type='text' name='username' value='".$username."' />";
$formdata .= "<br /><br />";
$formdata .= "<input type='submit' name='next' value='Next' />";
$formdata .= "</form>";
?>

Form2.php

<?php
$email = $_POST['email'];
$username =  $_POST['username'];
$formdata = "<form name='form2' action='form3.php' method='post' >";
$formdata .= "<input type='hidden' name='username' value='".$username."' />";
$formdata .= "<input type='text' name='email' value='".$email."' />";
$formdata .= "<br /><br />";
$formdata .= "<input type='button' name='back' value='Back' />";
$formdata .= "<input type='submit' name='next' value='Next' />";
$formdata .= "</form>";
?>

I assume you do know how to post the values to form1.php when you push the 'Back' button in form2.php
Also note that in form1.php 'email' field is hidden and in form2.php 'username' field is hidden.

Hope the above code snippet helps.

Sorry i missed the below 2 lines to be inclued in form1.php in the above post.

$email = $_POST;
$username = $_POST;

Sorry i missed the below 2 lines to be inclued in form1.php in the above post.

$email = $_POST;
$username = $_POST;

hi, Bhanuprakash;

Thanks for ur reply...Actually, i aint using one field per page..
Its just a sample..Actually each Form has more than 9 fields..
Thats y, i used multiform...
and i am not sure how to use the back button/..Can u explain me more abt the code..

Here are my codes:
which works good in the Forward way.

one.php

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>one</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="two.php">
  <label>
  Name:
  <input type="text" name="txt_name" id="txt_name" />
  </label>
  <p>
    <label>
    <input type="submit" name="submit" id="button" value="Next" />
    </label>
  </p>
</form>
<p>&nbsp;</p>
</body>
</html>

two.php

<?php
session_start();
$_SESSION['name'] = $_POST['txt_name']; 
echo $_SESSION['name']; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Two</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <label>Phone Number:
  <input type="text" name="txt_phone" id="txt_phone" />
  </label>
  <p>
    <label></label>
  </p>
  <table width="360" border="0">
    <tr>
      <th scope="row"><input type="submit" name="button2" id="button2" value="Back" onclick="form1.action='one.php';" /></th>
      <td><input type="submit" name="button" id="button" value="Submit" onclick="form1.action='result.php';" /></td>
    </tr>
  </table>
  </form>
</body>
</html>

result.php

<?php
session_start();
?>
<?php 
$db = "tryphy";
$link = mysql_connect("localhost","root","");
if (!$link)
{
die("Couldn't connect to MySQL");
}

mysql_select_db("tryphy",$link)
or die("Couldn't open $db: ".mysql_error($link));
$_SESSION['phone'] = $_POST['txt_phone'];
$n = $_SESSION['name'];
$p = $_SESSION['phone']; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Final</title>
</head>

<body>
<p>Name : <?php echo $_SESSION['name'];?></p>
<p>&nbsp;</p>
<p>Phone Number : <?php echo $_SESSION['phone'];?></p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<?php
$query = "INSERT INTO form(fname, fphone)"."VALUES('$n','$p')";
				mysql_query($query,$link)
					or die("Couldn't add data to add to \"Create Project\" table: 
".mysql_error($link));

				mysql_close($link);
				echo "Data added successfully";
?>
</body>
</html>

Can someone help me with ?
If press Back button from two.php it goes to one.php but cant see the data thats been typed in..
Pls help me with it..

Thanks,
Tryphy

forgive me for sounding really dense but wouldn't you just use

<input type="text" name="txt_phone" id="txt_phone" value=" <?php echo $n;?>" />

or use a

if (isset($n){echo "value=\"$n\"";}

hope it helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.