The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Validation Class Improvements - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: Validation Class Improvements (/showthread.php?tid=605) Pages:
1
2
|
Validation Class Improvements - faguss - 06-20-2017 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]]] 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 Code: ">"=>"Price" 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 Code: is_numeric Code: is_integer 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 Code: Input::get 43-44, 51, 57, 65 - My earlier change to Code: strlen 46-49 - Rule Code: required Code: true 160-189 - Value for the rule Code: in Code: [["display","value"]] 22, 2333 - In my view Code: _passed Code: _errors 191-198 - added rule is_datetime following this method. Example: Code: "is_datetime"=>"Y-m-d" Validation Class Improvements - karsen - 07-10-2017 Thought I'd share my own validation additions: https://pastebin.com/VSpRmJm6 Here's what I added: Date/Time checks- valid_date- checks if a date is in a valid format valid_month- checks if a month date is in a valid format valid_time- checks if a time is in a valid format valid_datetime- checks if a full datetime is in a valid format valid_futuredate- checks to see if a date is in the future Image checks- valid_image- checks if an image is of a valid type (there is no foolproof way to ensure it's actually an image, but is will weed out most bad images) unique_image- checks if an image name already exists image_width- checks if an image is wide enough image_height- checks if an image is high enough Misc. checks- valid_tracking- validates a tracking number using the Argo class package (https://github.com/dsposito/argo) in_array- checks if a value is a valid match from a given array zxcvbn- rates a password strength based on the Zxcvbn class package (https://github.com/bjeavons/zxcvbn-php). I use this in conjunction with the Javascript version for before/after form submission checks Validation Class Improvements - faguss - 07-13-2017 @karsen I've looked into your code. required_if - in my view you can just make required work properly (line 47 in my paste) instead of adding whole new rule. valid_datetime - it's a shame that you haven't tested it because the formats are different and it's returning error every time. Inspired I've implemented my version of this. >there is no foolproof way to ensure it’s actually an image, but is will weed out most bad images PHP manual advises against using getimagesize for validation. I apply finfo, imagecreatefromjpeg (not in validation class but in a separate function because I handle images after validation) and htaccess. From what I understand @firestorm uses finfo, getimagesize and optionally imagecreate. in_array - similar to in but you utilize array keys and I use sub-arrays. By the way, you can create unordered list in a single line: Code: $allowed = (empty($rule_value) ? "" : "<ul><li>") . implode("</li><li>", $rule_value) . (empty($rule_value) ? "" : "</li></ul>"); Validation Class Improvements - karsen - 07-15-2017 Would you mind doing a pastebin for your image validation code? I like that you condensed the in_array to one line, but it's easier for me to read as several. I've only recently gotten back into coding after around 10 years of little more than dabbling and had to play catch-up on all the PHP version and industry changes. The validations were one of the first things I modified and a lot of them were practice. Validation Class Improvements - faguss - 07-15-2017 >Would you mind doing a pastebin for your image validation code? It's in the class Generated_Form in the upload_image() method. Validation Class Improvements - karsen - 07-15-2017 Awesome, thank you! Validation Class Improvements - mudmin - 08-25-2017 I'm pushing these into 4.3 and also Karsen's valid_date case. Thanks so much guys! You're making this too easy! Validation Class Improvements - eeverts - 11-18-2017 Introducing a new rule: 'in'. In Code: Validate.php <pre> Code: case 'in': In user file, validation array: <pre> Code: 'gender' => array( Validation Class Improvements - eeverts - 11-18-2017 Oh, now I see that this function was proposed before yet. Excuse me. Validation Class Improvements - mudmin - 11-19-2017 I'm going to take a look at this for 4.3.5 Thanks! |