Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Numeric validation + fix 12 Dec 2012 11:29 #6028

Hello,

I found a minor issue with the numeric validation rule (using Cook 2.0). I have a required number field (int) in a table, for which 0 is an valid value. The JQuery validation works fine, but when the form rule is invoked from the server it generates an error when '0' is entered.

By looking at the code for the validation I spotted the issue. It is in in the /classes/rule.php class. When it does the required and empty check in the beginning of the testDefaults method it uses PHP's empty method to test if a value has been provided. However, this function considers values like 0, or 0.0, or '0' to be empty!

I fixed it as follows around line 96 in the testDefaults method:
		if ($required && empty($value))
		{
                    // valid when not numeric, or when it is a valid value
                    return (($element['validate']!="numeric")||(is_numeric($value)));
//			return false;
		}

Kind regards,

Misha
The following user(s) said Thank You: JoomGuy

Please Log in or Create an account to join the conversation.

Re: Numeric validation + fix 15 Dec 2012 14:22 #6112

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
You cannot write this code there, because testDefaults() is called by all rules, even not numeric.

I suggest you to write this in the numeric rule file.

Will check this...
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.058 seconds

  I found "cook" two days ago. Played around with it for a day and then within a day got rid of two legacy applications in IBM Lotus Domino Notes and replaced them with "cook". It was really easy. A piece of cake. Actually it was even easier than cooking. Cooking involves more work than developing with "cook". What can I say about "cook"? Great application great price for what it delivers great forum with a lot of information and fast responses active and friendly community fast forward moving development cycle So what should I say "Monsieur Le Cook"? Keep the good work going it will lead to success. Having become a paying member in the words of Edith Piaf may I say ..... non rien de rien ... je ne regrette rien. Vive La France.
FK (JED)
         

Get Started