Click to See Complete Forum and Search --> : session variables/forms
jagguy
11-06-2006, 05:09 AM
hi,
Here is a form element
<form action="process7qs.php" method="post">
Please type your name<p>
<input name="data1" size="40" maxlength="80">
<input type="submit" value="Send">...
and the user types in value and goes to another screen . Then the user gets back to this page again (like a preview screen and decided to come back and edit it again before submitting).
how can I set the form element "data1" to what was type in originally?
<?php
echo $HTTP_SESSION_VARS ["data1"];//the form name
?>
theRamones
11-06-2006, 06:18 AM
<?
session_start();
$data1 = $_POST['data1'];
session_register("data1");
header("Location: http://localhost/mainpage.php"); /* Redirect to main page */
exit(0);
?>
on mainpage.php
<?
session_start();
// and change data1 field to
?>
<input name="data1" size="40" maxlength="80" value="<?=$data1?>">
jagguy
11-06-2006, 08:28 PM
I think i need a complete example as it isn't working form me
callumd
11-06-2006, 08:57 PM
Replace
<input name="data1" size="40" maxlength="80">
with..
<input name="data1" size="40" maxlength="80" value="<?php if (isset($_POST['data1'])) { echo "$_POST['data1']"; } ?>">
callumd
11-06-2006, 09:04 PM
* I've altered my above code from what it originally was, so you may need to try it again, depending on when you saw this.
jagguy
11-06-2006, 11:37 PM
I get an error with that code.
Here is my whole code because I am just guessing at what to do now.
jagguy
11-06-2006, 11:40 PM
This is not working at all and i am confused.
I need help on this with a complete example. I can't find complete examples of code and that is the problem and nearly no good explanations.
My complete code is for the 2 forms is-
form1 where you enter the data and should have name value from when you typed it in before coming back here from form2 , but it does
nothing.
<?php session_start();
$_SESSION['form_data']['data1'] = $_POST['data1'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<h4>My test Form<p>
<form name='form_data' action="process7qs.php" method="post">
Please type your name<p>
<input name="data1" size="40" maxlength="80" value="<?php echo($_POST['data1']); ?>">
<p> Please type your productID<p>
<input name="data2" size="40" maxlength="80" ><br>
<p>Please type your qty<p>
<input name="data3" size="40" maxlength="10"><br><br>
<input type="submit" value="Send">
</form></p>
<p>*</p>
<h4></h4></h4>
</form>
</body></html>
form 2 where you decide you want to go back to form1
<?php session_start();
$_SESSION['form_data']['data1'] = $_POST['data1'];
?>
<html><body>
<?php
$data1= $_POST['data1'];
$data2 = $_POST['data2'];
$data3= $_POST['data3'];
echo "You typed in <br><br> <strong>name :</strong>".
$data1 . "<br><strong>email :</strong>" . $data2 . "<br> <strong>comments:</strong>"
. $data3."";
echo "<form action='form7qs.html' method='post'>";
echo " <input name=hidden value='<?php echo($_POST['data1']); ?>'>"; //error here as well
echo " <input type='submit' value='Back'>";
?>
</body></html>
callumd
11-06-2006, 11:56 PM
Code for your first page:
<?php session_start();
$_SESSION['form_data']['data1'] = $_POST['data1'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<h4>My test Form<p>
<form name="form_data" action="process7qs.php" method="post">
Please type your name<p>
<input name="data1" size="40" maxlength="80" value="<?php echo($_POST['data1']); ?>">
<p> Please type your productID<p>
<input name="data2" size="40" maxlength="80" ><br>
<p>Please type your qty<p>
<input name="data3" size="40" maxlength="10"><br><br>
<input type="submit" value="Send">
</form></p>
<p>*</p>
<h4></h4></h4>
</form>
Code for process7qs.php:
<?php session_start();
$_SESSION['form_data']['data1'] = $_POST['data1'];
?>
<html><body>
<?php
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
echo "You typed in <br><br> <strong>name :</strong>".
$data1 . "<br><strong>email :</strong>" . $data2 . "<br> <strong>comments:</strong>"
. $data3."";
echo "<form action=\"form7qs.html\" method=\"post\">";
echo "<input name=\"hidden\" value=\"" . $_POST['data1'] . "\"";
echo "<input type=\"submit\" value=\"Back\">";
?>
</body></html>
This will display the values from the first page on the second page, but I'm not exactly sure what you are trying to do, because the data1, data2, data3 values don't match up to the labels you have given them on the second page.
Also, just be careful with your HTML, you've opened and closed a few tags there that you didn't need to.
I hope there's enough here to get you where you need to go.
jagguy
11-07-2006, 02:52 AM
OK it works, it places the original value of name in the text box when you goto the form2 and decide to click on back, it then appears on form1 again.
I wanted to use session variables but it appears I am just posting data, how can I use session variables for this problem?