Form validation callback return value |
[eluser]Anonymous[/eluser]
hi there, Anyone knows why my callback return value is being ignored ? Code: $this->form_validation->set_rules('groningen', 'groningen', 'callback_username_check'); the callback Code: function username_check() { Code: var_dump($this->input->post('groningen'));
[eluser]Eric Barnes[/eluser]
Not really sure what the goal is by returning a string of testing but that is not how it is designed. Please see: http://ellislab.com/codeigniter/user-gui...#callbacks
[eluser]adityamenon[/eluser]
I don't think setting a form_validation rule will automatically change the POSTed data... why are you var_dump()ing $this->input->post('groningen')?
[eluser]Anonymous[/eluser]
the documentation says it should work that way. "If your callback returns anything other than a boolean TRUE/FALSE it is assumed that the data is your newly processed form data."
[eluser]adityamenon[/eluser]
Are you dumping the data _after you've done this: $this->form_validation->run()?
[eluser]mr lister[/eluser]
I think you are misunderstanding the documentation. In your callback function, carry out what ever conditional statements you need on the POSTed data, then return the boolean result as either TRUE/FALSE depending on the result. I agree with adityamenon, the form validation / callback function will not change your POSTed form data, you are only validating the form data based on set criteria. The example: Code: if ($str == 'test') The documentation gives the above example, as Eric pointed out with the user guide link.
[eluser]Ashes-to-Ashes[/eluser]
It was working for me, with return $value instead of return false. But now it's not so I think there may be more to this.
[eluser]Ashes-to-Ashes[/eluser]
In fact, I just verified that YES you can return a value instead of true or false. It is working on one of my callbacks but not the other. Non working function Code: public function _tag_number_check($str) Working callback Code: public function _account_number_check($str) I am guessing that my particular error is is somewhere else, but I don't know where or how.
[eluser]Ashes-to-Ashes[/eluser]
Okay, my callback is now correctly returning the tag number as the new post data. It was a bug in my call back rule, I had specified the wrong field name. But, this should prove that it will work for you given that you have the correct CodeIgniter version. I have 2.0.1
[eluser]Aken[/eluser]
Callbacks can indeed return a revised or completely new value for the provided form element. As long as it is not boolean. Remember that validation rules are run in order from left to right, and that have to call $this->form_validation->run() in order for the new value to show up. |
Welcome Guest, Not a member yet? Register Sign In |