Re: How to deal with errors in forms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 24 Aug 2006 11:40:17 +0200, Merlin wrote:

> Hi there,
> 
> I do have a form where there is also a field with max 2000 characters 
> the user can put in.
> 
> Now before processing the data with php, I do a checkin the script for 
> certain criterias if something lookes wrong I do redirect him to the 
> original form with inserting the data he has entered. I do this via GET
> e.g.: ?title=test&body=blablub
> 
> That works fine with one exception. If the user does enter 2000 
> characters (or a lot c.) they do get transfered via URL as well and that 
> is not possible. Firfox for example then simply displays a blank page!!! 
> It would be fine if he would return with just a few less characters, but 
> at least display the error message I am providing.
> 
> Now, 2 questions:
> 1) Does anybody know why firefox is shoing a blank page? If the URL does 
> contain less characters, lets say 100 everything works fine.
> 2) How could I possibly save his entry? Maybe with the help of a cookie? 
> But then, I do redirect to the page. So I do send a header. As far as I 
> know this only once possible?
> For example:
> setcookie('bla test');	 
> HEADER("Location:".$data[rurl]."?error=".$error.$parameter);
> 
> I would rather not like to use the help of a database.
> 
> Any ideas?
> 
> Regards,
> 
> Merlin

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.

HTH

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux