Jump to content

session callback


jagguy

Recommended Posts

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?

<?php


echo $HTTP_SESSION_VARS ["data1"];//the form name

?>


Link to comment
https://forums.phpfreaks.com/topic/26301-session-callback/
Share on other sites

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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120260
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120261
Share on other sites

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 Session
session_start();

// Print form
echo <<<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 Session
session_start();

// Make sure they've posted the form
if (!isset($_POST)){
  header("Location: register.php");
}

// Put the values into session variables
foreach ($_POST as $name => $value){
  $_SESSION[$name] = $value;
}

// Ask the user to confirm
echo "Is the following info correct...<br>\n";

// echo all your $_POST variables here
echo "Firstname: {$_POST['firstname']}<br>\n";

// Ask the user to go back if incorrect
echo "If info is incorrect then <a href=\"register.php\">go back</a><br>\n";
?>[/code]

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120841
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.