The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation Class Improvements
#1
Somehow my topic disappeared while I was editing so I'm reposting it.

https://pastebin.com/KmhvbPFh

46,51 - Replaced empty() with strlen()==0 because if the input was "0" (number zero) then the validation wouldn't work.



78-87 - Optionally you can pass array to the unique for a more complicated query (provided you have this patch). For example:
Code:
"unique"=>["tablename", ["and", ["SomeData","=",1], ["OtherData","=",2]]]
Also it will fail validation if query returned an error (which the original did not do).


110-147 - Added rules <, >, <=, >=, !=, == for comparing numbers. They will automatically check if value is a number so there's no need to stack it with is_numeric. For example:
Code:
">="=>25
(equal to 25 or greater ). You can also compare it against other fields. For example:
Code:
">"=>"Price"
(greater than the number in the "Price" input)


149-152 - Added rule is_int for excluding floats.
Code:
"is_int"=>true


209-210 - In function addError() added condition to prevent error message duplication.

===

EDIT:

54-55, 62-63, 70-73 - One issue with using array keys as rules is that you can't stack them. I've added an option to pass an array to rules: min, max, matches, <, >, <=, >=, !=, ==. For example:
Code:
">"=>[25,"Price"]

154-158 - Added rule is_timezone for verifying time zone name.
Code:
"is_timezone"=>true

100, 149 - Added
Code:
is_num
(synonymous with
Code:
is_numeric
). Added
Code:
is_integer
(synonymous with
Code:
is_int
)

160-189 - Added rule in for matching string lowercase.
Code:
"in"=>["a","b","c"]

30, 38-41 - If value is an array then
Code:
sanitize
will return an error. Because I use
Code:
Input::get
I don't want to sanitize again so I added optional argument to skip it

43-44, 51, 57, 65 - My earlier change to
Code:
strlen
screwed me over because values couldn't be arrays. Added condition to detect value type.

46-49 - Rule
Code:
required
now needs to be set to
Code:
true
in order to work

160-189 - Value for the rule
Code:
in
can now be array. Optionally containing sub-arrays where
Code:
[["display","value"]]

22, 2333 - In my view
Code:
_passed
is an unnecessary state so I've removed it. Better to just check if
Code:
_errors
isn't empty which I can do directly now because it's public.

191-198 - added rule is_datetime following this method. Example:
Code:
"is_datetime"=>"Y-m-d"
  Reply


Messages In This Thread
Validation Class Improvements - by faguss - 06-20-2017, 01:18 PM
Validation Class Improvements - by karsen - 07-10-2017, 07:29 PM
Validation Class Improvements - by faguss - 07-13-2017, 09:48 PM
Validation Class Improvements - by karsen - 07-15-2017, 03:33 PM
Validation Class Improvements - by faguss - 07-15-2017, 03:41 PM
Validation Class Improvements - by karsen - 07-15-2017, 04:31 PM
Validation Class Improvements - by mudmin - 08-25-2017, 12:42 PM
Validation Class Improvements - by eeverts - 11-18-2017, 07:32 PM
Validation Class Improvements - by eeverts - 11-18-2017, 07:41 PM
Validation Class Improvements - by mudmin - 11-19-2017, 11:53 PM
Validation Class Improvements - by eeverts - 11-20-2017, 07:25 AM
Validation Class Improvements - by mudmin - 11-20-2017, 04:06 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)