Jump to content


Photo

How to keep the previous data??


  • Please log in to reply
7 replies to this topic

#1 evon83

evon83
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 24 September 2006 - 03:09 AM

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!

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 05:38 AM

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

<?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;
}

?>


#3 evon83

evon83
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 24 September 2006 - 06:27 AM

no....i can;t do it on the same page!
I cannot agree with it...

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


#4 evon83

evon83
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 24 September 2006 - 06:30 AM

does anyone have the code that has like 2 pages.....???
please please help.....

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 24 September 2006 - 06:39 AM

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. 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 24 September 2006 - 06:46 AM

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

#7 evon83

evon83
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 24 September 2006 - 10:09 PM

can u show me the sample code of the session code please??
thanks!

#8 evon83

evon83
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 24 September 2006 - 10:29 PM

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!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users