Simplified Error Handling
Posted: Sat Jul 22, 2006 12:12 am
Let's say I have a form. Each item in the form can have multiple errors. (too short, too long, invalid type, etc)..
I have a class that validates the posted data in the form..
Now, when I redisplay the form because of an error, I want to highlight the background of the specific question that didn't validate. The form is called from a template file.
I thought about assigning each error an id.. like this..
In this case I could check to see if this error was set and highlight the question when I redisplay the form.
But if I do that, I'll lose some of the errors because a question might have more than 1 error at a time. ie too long and contains invalid characters.
So... do I have to create a 2nd variable to indicate which question to highlight?
I'm just wondering how others would do something like this.
The form would look something like this..
This might sound like a weird question, but I am putting some serious effort into reducing code. I'm cutting it everywhere I can..
I have a class that validates the posted data in the form..
Code: Select all
if ($this->iAgree != 'checked')
{
$this->errors[] = 'You must agree to the terms of service.';
}I thought about assigning each error an id.. like this..
Code: Select all
if ($this->iAgree != 'checked')
{
$this->errors[2] = 'You must agree to the terms of service.';
}But if I do that, I'll lose some of the errors because a question might have more than 1 error at a time. ie too long and contains invalid characters.
So... do I have to create a 2nd variable to indicate which question to highlight?
I'm just wondering how others would do something like this.
The form would look something like this..
Code: Select all
<td <?php if (isset($this->errors[2])) echo 'class="redBackground"'; ?>><input type="text" name="something" value="<?php echo $this->something; ?>" /></td>