nopsoon
|
| Posted: 07/06/2002, 3:46 AM |
|
If you set an integer fields required property = true, it is impossible to enter the value zero in, since you get an error message saying the field is required.
In Classes.php, the Validate function does the following:
if($this->Required && $this->Value == "" && $this->Errors->Count() == 0)
In PHP, comparing 0 to "" evaluates to true, hence making the code reject 0 as an input, when it should be allowed, since the Validate() function is incorrectly assuming the field has been set to an empty string. In PHP, an empty string and zero are equal.
The solution is simple, replace the line above with this in Classes.php:
if($this->Required && "$this->Value" == "" && $this->Errors->Count() == 0)
This works because "$this->Value" will be evaluated as a string containing the entered value, that is, the comparison ends up being "0" == "", giving us the desired result, rather than 0 == "" which evaluates to true.
|
|
|
 |
Chris K.
|
| Posted: 07/06/2002, 5:13 AM |
|
It would be even better to use === PHP operator which doesn't perform type casting. 0 === "" is false.
|
|
|
 |
|