jagguy Posted November 6, 2006 Share Posted November 6, 2006 hi,There is a form element like this in html<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?<?phpecho $HTTP_SESSION_VARS ["data1"];//the form name?> Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/ Share on other sites More sharing options...
HuggieBear Posted November 6, 2006 Share Posted November 6, 2006 Change the form to this:[code]<form action="process7qs.php" method="post">Please type your name<p><input name="data1" size="40" maxlength="80" value="<?php echo $HTTP_SESSION_VARS['data1']; ?>"><input type="submit" value="Send">...[/code]Don't forget to use session_start() at the top of your pages before outputting anything else.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120260 Share on other sites More sharing options...
Orio Posted November 6, 2006 Share Posted November 6, 2006 On process7qs.php, enter $_SESSION['data1']=$_POST['data1'] (make sure you have session_start() on the top of th page!).Then in the form itself you should have something like this:[code]<?php session_start() ?>//some HTML here<form action="process7qs.php" method="post">Please type your name<p><input name="data1" size="40" maxlength="80"<?php if(isset($_SESSION['data1'])) echo "value=\"".$_SESSION['data1']."\"; ?>><input type="submit" value="Send">[/code]Orio.EDIT- I am getting slower as the years pass :D Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120261 Share on other sites More sharing options...
jagguy Posted November 7, 2006 Author Share Posted November 7, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120738 Share on other sites More sharing options...
HuggieBear Posted November 7, 2006 Share Posted November 7, 2006 Both mine and Orio's examples use session variables as specified in your first post.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120834 Share on other sites More sharing options...
jagguy Posted November 7, 2006 Author Share Posted November 7, 2006 i used this but I get the value from a post?value="<?php echo($_SESSION['form_data']['data1']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120839 Share on other sites More sharing options...
HuggieBear Posted November 7, 2006 Share Posted November 7, 2006 Yes, you get the value via the $_POST variable but then assign it to a session variable by using something like [code=php:0]$_SESSION['username'] = $_POST['username'];[/code] Then you can use [code=php:0]$_SESSION['username'][/code] on any page where you specify [code=php:0]session_start();[/code] at the top.So [b]register.php[/b] looks like this:[code]<?php// Start Sessionsession_start();// Print formecho <<<HTML<form name="register" method="post" action="confirm.php"><input type="text" name="firstname" value="{$_SESSION['firstname']}"> Firstname<br><input type="text" name="lastname" value="{$_SESSION['lastname']}"> Lastname<br><input type="text" name="email" value="{$_SESSION['email']}"> Email Address<br><input type="text" name="username" value="{$_SESSION['username']}"> Username<br><input type="password" name="password"> Password<br><input type="submit" name="submit" value="Submit"></form>HTML;?>[/code]and [b]confirm.php[/b] looks like this:[code]<?php// Start Sessionsession_start();// Make sure they've posted the formif (!isset($_POST)){ header("Location: register.php");}// Put the values into session variablesforeach ($_POST as $name => $value){ $_SESSION[$name] = $value;}// Ask the user to confirmecho "Is the following info correct...<br>\n";// echo all your $_POST variables hereecho "Firstname: {$_POST['firstname']}<br>\n";// Ask the user to go back if incorrectecho "If info is incorrect then <a href=\"register.php\">go back</a><br>\n";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120841 Share on other sites More sharing options...
jagguy Posted November 8, 2006 Author Share Posted November 8, 2006 ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-121349 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.