Re: check a variable after EACH function
| From: | Paul M Foster | Date: | Wed, 01 Jul 2009 03:59:34 +0000 |
| Subject: | Re: check a variable after EACH function | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294780@lists.php.net to get a copy of this message | ||
On Tue, Jun 30, 2009 at 11:21:03PM -0400, Phpster wrote:
> On Jun 30, 2009, at 10:48 PM, Paul M Foster <paulf@quillandmouse.com>
> wrote:
>
<snip>
>>
>> FWIW, I've had to do this exact thing with regard to form validation,
>> except I'm not looping. Check each condition, and if it fails, never
>> mind validating the rest of the fields.
>>
>
> Isn't that a little rough on the user? Wouldn't a better user
> experience be to check all the fields and report all errors back to
> the user in one pass, rather than after each element that fails?
<blush>
Well, yes. Early on I tended to do it this way, but I made my error
handling more sophisticated over time.
Actually, where I do something like this now is on some blog software I
wrote. There are numerous fields to be filled out, and if all are
filled out correctly, it updates a database and dumps some files to
disk. At each field check, I increment an error count variable if the
user screws up. And before I check each field, I check the error count.
If there are errors, then I may not update the database and dump the
files, so there's no point in checking the contents of certain fields.
For example, if the user didn't provide a title for the post, I'm not
going to go through the process of XSS checking on their post content,
since I'm not going to store it until they give me a title. I'll report
to them on the missing fields, though, and allow them to repair.
Paul
--
Paul M. Foster