I am using a form that uses process page to verify and then process all info. If something is wrong or is missing the message tells the users to go back to the page and fix it. However, when they do it, all other information that they put in is not shown in the fields. How can I make it so whatever they put in will show.
Remember input history
1.2k views Asked by AAA At
3
There are 3 answers
0
On
make the validation in the same page with javascript or ajax(if you need to check in the server side)
then you don't lose any data
you can find in the web many examples (look for form validation with ajax)
like this article : http://jqueryfordesigners.com/demo/ajax-validation.php
2
On
A simple solution would be to store all POST data inside of a SESSION upon posting it.
if($_POST){ // if we have any POSTed variables...
$_SESSION['postdata'] = $_POST; // set a browser session with all of the values
}
Then, on your form page, check if postdata exists, and if so, fill input values.
if($_SESSION['postdata']){ // if postdata exists
$p = $_SESSION['postdata']; // retrieve values in a new variable
unset($_SESSION['postdata']); // unset session, because you don't want this post data to travel all around your website
/* for each input or whatever you got there... */
echo '<input name="your-key-here" type="text" value="'. $p['your-key-here'] .'" />';
}
Something like that! Have fun!
The best way is to do the validation on the same page and only redirect to another page when that succeeded:
Alternatively: use sessions.