Jump to content

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

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?
Link to comment
https://forums.phpfreaks.com/topic/26301-session-callback/#findComment-120738
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.