Documented research indicate that on Fri, 25 Aug 2006 13:18:25 +0200, "Ivo
F.A.C. Fokkema" wrote:

> 
> You might also try to process the results from the form first, and then,
> if errors are found, display the form again and put the data in there
> yourself. No need to send the user back and forth. But you may need to
> restructure your code a little. I personally always use this method.
> 
> 1) Check if form is sent.
> 1a) True? Check form contents. Put errors in a variable. If there are no
> errors, do whatever you need to do.
> 1b) False? Set all form fields to the default values (probably empty strings).
> 
> 2) Check if error variable exists.
> 2a) True? Print error variable on the screen.
> 
> 3) Print form, and load values in them.

The above method is basically what I use with great success. I've simply
added my own alerthandler functions, meaning the form checking part sets a
variable called $alert_level to a value between 0 and 3, 0 = no errors, 1 =
notice, 2 = warning, and 3 = error, and then the handler itself checks what
kind of alert to put out and displays a box coloured to match the alert
level. The main reason for doing it like that is because I wanted something
simple that I could reuse across all my pages, so alert messages look
similar - people pay more attention to them if all your pages use the same
method of notifying them of problems and errors.
The alert_handler uses a second variable, $alert_message, that the form
checker uses to tell exactly where the problem is, to avoid one of the
"There was an error in your input" situations.

On top of that, I'd like to suggest (or actually recommend) using POST
instead of GET, especially when you use 2000 char fields. PHP doesn't care
either way, but if you use POST you won't have the problem of field
contents being cut off because they won't fit in the URL. And you can keep
all your variable names the same, or even make them longer and easier to
remember perhaps.


Rene

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to