[SOLVED] Form validation callback method in MODEL instead of controller -- Read me if you want the answer. |
[eluser]Mirge[/eluser]
So in my model I have: Code: $this->form_validation->set_rules('how_completed', 'How is the transaction completed?', 'callback_how_completed'); And the callback is NOT being called. Thoughts?
[eluser]Mirge[/eluser]
And apparently it doesn't want to give me a log file. /sigh. EDIT: fixed log file issue, but don't see anything in log that'd help.
[eluser]Mirge[/eluser]
I've also tried creating an isolated test... this also is NOT calling my callback method. Any idea why? Code: <?php Here's the output: Code: before
[eluser]Mirge[/eluser]
edited, maybe it can't find the callback in the model, it has to be in controller?
[eluser]Mirge[/eluser]
Sigh. SO... you can't have form validation with callbacks in a model in CI by default? Unreal... unless I'm just missing something. EDIT: Ran into this: http://codeigniter.com/wiki/MY_Form_vali...to_Models/ But it also did not work. Out of time, I just put the callback methods in the controller and called it good for now, but would REALLY love for somebody to chime in with a working solution so I can move the callback methods back into the model. Thanks!
[eluser]Mirge[/eluser]
Not able to find a working MY_Form_validation class that'll allow callbacks in model. Anybody know of a working one?
[eluser]Mirge[/eluser]
After MUCH headache... I decided to revisit the previous URL and re-try the code. It still didn't work. I started tracing through it... and the example shows you're supposed to invoke a callback method in the MODEL via: callback_methodname_model[modelname] So, I continued tracing through the code... echo statements & what not. Then I discovered that $rule was NOT saving the [modelname] portion. Seconds later, I found the regular expression: Code: if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) needless to say, I let out a sigh of relief. \w won't match brackets. I changed the regex to: Code: if(preg_match("/(callback_[\w\[\]]+)/", implode(' ', $rules), $match)) And it's now calling the correct validation method within the model specified. All is right with the world again. Figured I'd share... since the only forum results I could find via searching were not helpful. Hopefully this saves somebody else the hassle/headache. |
Welcome Guest, Not a member yet? Register Sign In |