Re: quick form question
| From: | Matt Schroebel | Date: | Thu, 08 Aug 2002 16:46:19 +0000 |
| Subject: | Re: quick form question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111682@lists.php.net to get a copy of this message | ||
"Alexander Ross" <alexross@bleen.net> wrote in message
news:20020808162929.17218.qmail@pb1.pair.com...
> I have a .php with a simple form in it to populate a table in a mysql db.
> When the user clicks submit, I check to make sure he/she entered the
> required info and if all is well, I add the data to teh DB. If he/she
left
> out some info, I echo "You left out some info" and I redisplay the form.
> When I do this all the info that the user typed originally is gone. Whats
> the easiest way to put back what he/she already typed? Thanks
Similar to the other posts:
What I do on forms is to first capture the input into another variable such
as:
$firstName = trim($_POST['firstName']);
If it's a post request:
I validate all of the input.
If everything is fine, I addslashes, insert/update the database, and
re-direct to another page that indicates sucess in one way or another.
Otherwise I load error messages, and fall through to the get handler which
displays the form.
In the get handler you can use the value="<?php echo $firstName ?>" to
retain the text input. Radio buttons, checkboxes and selects are a little
harder and I wrote functions for that.