Jump to content

Archived

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

evon83

How to keep the previous data??

Recommended Posts

Hello there!

i know this sounds too eay for you guys but i still couldnt solve the problems!

I have this form fillin....
and when user press the enter button,
and the php code will runs the error checking..

if there's errors, messages will be displayed and ask them to go back...
however, how to keep the previous data that they have entered???

i know if users have to repeat key in the same thing again and again, that would drive them nuts...

please help!
and provide some sample code!

thanks!

Share this post


Link to post
Share on other sites
You dont send it to another script to validate - do this in the same script, here is a basic example of how it can be done
[code]

<?php

if(isset($_POST['submit']))
{

if(!empty($_POST['email']))
{
  // ok
  echo "Thank you!";
  $done = 1; // done is set, hiding form
}
else
{
  // email missing
  echo "Please fill inn required fields";
}

}

if(!$done)
{
echo <<<__HTML

<form method="post" action="this_page.php">

<input type="text" name="email" value="$email" />

<input type="submit" value="Do send" name="submit" />

</form>

__HTML;
}

?>
[/code]

Share this post


Link to post
Share on other sites
no....i can;t do it on the same page!
I cannot agree with it...

does anyone has those in 2 pages???!!

Share this post


Link to post
Share on other sites
a) why do you want it in 2 pages?

b) the above code assumes register globals is set to ON. in the form, use value='{$_POST['email']}'  instead of $email.

c) if you really want to do it in 2 pages, you're going to have to
  1) make a cookie (user dependant)
  2) start a session (best option)
  3) store the information in a db or flatfile (not really convenient)

to make a session:

at the beginning of both of your scripts, put

session_start();

this must be before anything else (except your <?php tag)

then in your form, use $_SESSION['email'] as the input value for the email

in your processing script, set $_SESSION['email'] = $_POST['email'] if there is an error, kick them back to the form with a header or something. 

Share this post


Link to post
Share on other sites
quote: the above code assumes register globals is set to ON

sorry - mistake

i agree on using sessions if you absolutely need a non-one page script

Share this post


Link to post
Share on other sites
This is my sample code:

Page1:

<?php
   
session_start();
?>

<form action="session2.php?" method="Post">
        <table align="center" border=0 cellspacing=5 cellpadding=0 width="100%">


        <table>
          <tr>
        <th align="left">Address :</th>
              <td><input type="text" size = "55" name="address1"/></td>
              <td><input type="text" size = "55" name="address2"/></td>
          </tr>
        </table>
        <center><input type="submit" name="submit" value="Submit"><input type="reset" Value="Reset"/></center>
        </form>


page2:
<?php
// page1.php

session_start();

$_session['address1']=$_POST['address1'];
$_session['address2']=$_POST['address2'];

echo "1:".$_session['address1'];
echo "<br>2:".$_session['address2'];

session_destroy();

-------------------------------------------

my question is:
after i have clicked on page2....i wanna go back to page1, so click on the back button...
and when i do that, the data that i have keyed in previously has been erased automatically....
how to keep my previous data??

please help!

thanks!

Share this post


Link to post
Share on other sites

×

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.