evon83 Posted September 24, 2006 Share Posted September 24, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/ Share on other sites More sharing options...
alpine Posted September 24, 2006 Share Posted September 24, 2006 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]<?phpif(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] Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97493 Share on other sites More sharing options...
evon83 Posted September 24, 2006 Author Share Posted September 24, 2006 no....i can;t do it on the same page!I cannot agree with it...does anyone has those in 2 pages???!! Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97513 Share on other sites More sharing options...
evon83 Posted September 24, 2006 Author Share Posted September 24, 2006 does anyone have the code that has like 2 pages.....???please please help..... Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97516 Share on other sites More sharing options...
.josh Posted September 24, 2006 Share Posted September 24, 2006 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, putsession_start(); this must be before anything else (except your <?php tag)then in your form, use $_SESSION['email'] as the input value for the emailin your processing script, set $_SESSION['email'] = $_POST['email'] if there is an error, kick them back to the form with a header or something. Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97523 Share on other sites More sharing options...
alpine Posted September 24, 2006 Share Posted September 24, 2006 quote: the above code assumes register globals is set to ONsorry - mistakei agree on using sessions if you absolutely need a non-one page script Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97525 Share on other sites More sharing options...
evon83 Posted September 24, 2006 Author Share Posted September 24, 2006 can u show me the sample code of the session code please??thanks! Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97788 Share on other sites More sharing options...
evon83 Posted September 24, 2006 Author Share Posted September 24, 2006 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.phpsession_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! Quote Link to comment https://forums.phpfreaks.com/topic/21827-how-to-keep-the-previous-data/#findComment-97802 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.