> I want to validate a form (in page1.php) to check if the
> user has entered a correct email-adress and more, and if he
> needs to correct some fields, I'd like to display the form
> again with all correct values filled in and the incorrect
> fields hightlighted.
I tend to do this sort of thing using includes and a single page. If
it's the first time being loaded (no post data) then just display the
form. If it's been submitted then process the data and decide what to
do from there. If there are errors, redisplay the form showing errors
that need to be corrected. If there's no errors, move along to the next
stage in the process.
> To make it a bit more difficult I've decided to POST to another file
> (post.php) which validates the information and redirects the
> user (with Header - Location) to page1.php if he has to
> correct the errors. If the form is correctly filled in then
> he will be redirected to page2.php. This is to prevent the
> browser for asking him if he wants to repost data if he hits
That's a browser decision based on the existence of post data - in other
words, just because the form posts to a different file doesn't mean that
if you hit reload it won't re-post the data.
> hightlight the bad fields. I don't want to stick it in the
> URL since it would be too ugly, but I do have session
> variables I can stick them in. Is this the way to go? Or is
> there a better solution?
There are ways to do it - cookies or hidden forms spring to mind - but
first it's worth working out if the effort is worth it. It won't
prevent a page refresh from re-posting data (although you could test for
that in your php and deal with it accordingly).
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php