I cheat and just include the original form on error ...

Almost all my input values are set to PHP variables in the form. The 1st
time through none are set, so the values are blank. After submitting the
form, I check for validity. If there are errors I mark the errors, generate
an error string, and include the form. That way all previously typed in data
remains in the form without me having to tell the user to hit the "back"
button, and there's no horribly long URL string resetting all those values.

There's a bit more work than that (using htmlspecialchars et al.) but if you
start creating forms with error checking & indication in mind it's really
easy to do validation and redisplay if necessary.

Mark C.

> > Hi,
> >
> > I wonder if someone could tell me whether or not the following is
> > possible?
> >
> > I have an HTML form which passes a username and password to a PHP script
> > for validation. If either is not valid, I would like it to return to the
> > previous page - carrying with it a variable plus the submitted form
> > information...
> >
> > =-=-=-=-=-=-=-=-=
> > if (strlen ($password1) <4 ) {
> >    $err = "Password must be more than 4 characters long";
> >    header("Location:http://somelocation.php";);
> >    // ^-- at the location, the $err and form variables will be available
> >
> >    exit;
> > }

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to