Form validation and native PHP functions |
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?
"Well, if crime fighters fight crime and fire fighters fight fire, what do freedom fighters fight?"
06-20-2017, 05:33 AM
(This post was last modified: 06-20-2017, 05:34 AM by Martin7483. Edit Reason: typo )
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.
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?
"Well, if crime fighters fight crime and fire fighters fight fire, what do freedom fighters fight?"
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
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 |
Welcome Guest, Not a member yet? Register Sign In |