RE: [PHP] How to make a form retain its info
| From: | Craig Vincent | Date: | Thu, 27 Jul 2000 19:40:25 +0000 |
| Subject: | RE: [PHP] How to make a form retain its info | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8647@lists.php.net to get a copy of this message | ||
> Interesting.. What do you trigger on to decide wether to
> "pre-load" the form?
> Or do you check each field, and fill or not depending on wether something
> was there?
>
> I like the idea of flagging the errored field, but this script
> seems to be
> getting fat pretty quickly.
> You'd have to pass back something to point to the errored field(s)..
>
> Do you have a template for this?
Not really...all my forms have this feature and it works quite well :)
This would be a typical setup for me
page: signup.html
<?
$errmsg = '';
$emailcolor = 'black';
$namecolor = black';
if ($action == 'process') {
if (!$email) { $errmsg .= 'You need to enter an email address<BR>';
$error=1;
$emailcolor = 'RED';
}
if (!$name) { $errmsg .= 'You need to enter a name<BR>';
$error=1;
$namecolor = 'RED';
}
if (!$error) { /* successful */ exit; }
}
?>
<HTML>
<BODY>
<? echo $errmsg; ?>
<FORM METHOD="POST" ACTION="signup.html">
<INPUT TYPE="hidden" name="action" value="process">
<FONT COLOR="<? echo $emailcolor; ?>">Email Address<INPUT
TYPE="text"
name="email" value="<? echo $email; ?>"></FONT><BR>
<FONT COLOR="<? echo $namecolor; ?>">Name<INPUT TYPE="text"
name="name"
value="<? echo $name; ?>"></FONT><BR>
<INPUT TYPE="submit" name="Submit">
</FORM>
</BODY>
</HTML>
That is incredibly basic but will do the trick...and it's fairly easy to add
additions to the filter or incorporate extra form fields. It's effecient
because it only requires one call to the server...plus if the form
information is incorrect, everything is already passed back to the form with
no additional effort.
Sincerely,
Craig Vincent
Senior Programmer
Virtual Centric
2bunnyhop@home.com