Welcome Guest, Not a member yet? Register   Sign In
Extending Validation class to call a method that returns a modified value
#1

[eluser]housecor[/eluser]
I understand how to extend CI's validation class to add additional methods that return bool, but how do I create method that modifies the value being validated?

For example, you can call native PHP functions in your validation like this:

"required|strtoupper"

I'd like to extend the validation class so I can call blank_to_null as part of my validation so any fields posted blank are converted to null before db insertion. Anyone have an example of how to pull that off?
#2

[eluser]coolgeek[/eluser]
Quote:If your callback returns anything other than a boolean TRUE/FALSE it is assumed that the data is your newly processed form data.

Form Validation: Codeigniter User Guide
#3

[eluser]Eric Cope[/eluser]
I extend the form_validation class instead of callbacks so I can use the functions on more than one controller. It would be nice if these functions had the same features. Is that possible?
#4

[eluser]danmontgomery[/eluser]
Have you tried it?
#5

[eluser]Eric Cope[/eluser]
[quote author="noctrum" date="1268706200"]Have you tried it?[/quote]

I assume you are talking about my comment. I have tried it, but it does not work. I could be mistaken though, since my testing environment included no-coffee-late-night-programming...
#6

[eluser]WanWizard[/eluser]
Odd.

Looking at the code in the _execute method, it does check for non-bool return values, on callbacks, internal PHP functions, and form_validation methods...

Code:
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;




Theme © iAndrew 2016 - Forum software by © MyBB