CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

  Problem in CCS with PHP 4 and required property

Print topic Send  topic

Author Message
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.

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.