![]() |
Form validation and native PHP functions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Form validation and native PHP functions (/showthread.php?tid=68288) |
Form validation and native PHP functions - cvetan - 06-20-2017 I don't understand how the native PHP functions are to be used in form validation. For instance, i've set this rule 'required|trim|strtolower'. For test string: Code: ' Test' it doesn't show error, validation passes. If i missunderstood, what should native functions do in form validation? RE: Form validation and native PHP functions - Martin7483 - 06-20-2017 The only rule that could fail on validation is the required rule. Because something has been provided it will pass as valid. trim and strtolower are string prepping functions. All you are doing is telling CI to run the native PHP functions to make sure all white space is removed and that all characters are lowercase. If you want the validation to fail based on these rules you should create your own validation rule to do so. RE: Form validation and native PHP functions - cvetan - 06-20-2017 One other thing. I've set 'required|regex_match[/pattern/]'. And it didn't show required error, went straight to regex match on empty input? RE: Form validation and native PHP functions - Martin7483 - 06-20-2017 I believe using native PHP methods is like using a custom callback method. They are always called first. Then followed by all other set rules I had a solution for it but for reasons unknown that thread was removed. I do still have the code and will look it up for you RE: Form validation and native PHP functions - Martin7483 - 06-20-2017 If you always want required rules to run first you can do the following Create a MY_Form_validation class in ./application/libraries/ Add this code to it PHP Code: <?php |