RE: [PHP] quick form question
| From: | Mark Middleton | Date: | Thu, 08 Aug 2002 16:40:22 +0000 |
| Subject: | RE: [PHP] quick form question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111681@lists.php.net to get a copy of this message | ||
Depending on how high your error reporting is set, this may or may not give
you an error (usually doesn't)
<form...>
<input type="text" name="firstname" value="<?= $firstname;
?>">
<input type="text" name="lastname" value="<?= $lastname;
?>">
</form>
Therefore, when it's first run, all those fields have no value, and will
leave the value="" empty...
Upon a re-submit, it will return the values entered in the form.
There are some more ways to do this for select boxes, radiobuttons and
checkboxes...
(This is how I do it, others may have a much cleaner, nicer way)
<select name="whatever">
<option value="1"<? if ($whatever == "1") { print "
selected"; }?>>one</option>
<option value="2"<? if ($whatever == "2") { print "
selected"; }?>>two</option>
</select>
I hope this helps!
-Mark
> 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