Form Validation Callback for Matching Password |
[eluser]RMinor[/eluser]
I am trying to validate a form that administrators will use to change their passwords. I am salting and using sha1() on the password when I store it in the database. When an administrator is changing their password I am checking that the password they enter as their old one is actually correct. For this I need to pass in their id and the entered password value. How do I do this using the form validation callback feature and multiple input parameters to it? Controller Code: /** Model Code: /**
[eluser]CroNiX[/eluser]
Code: $this->form_validation->set_rules('old_password', 'Old Password', "trim|required|callback_password_matches[$admin_id]"); The first value passed to your callback will always be the form field value, any additional values can be passed within brackets (see above) and will be received as the 2nd parameter of the callback. Code: public function password_matches($submitted_value, $admin_id)
[eluser]RMinor[/eluser]
Cool, I did not know that. Thanks for the help. Something like this should be in the user guide, unless I just missed it.
[eluser]CroNiX[/eluser]
http://ellislab.com/codeigniter/user-gui...#callbacks Quote:To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix. If you need to receive an extra parameter in your callback function, just add it normally after the function name between square brackets, as in: "callback_foo[bar]", then it will be passed as the second argument of your callback function. |
Welcome Guest, Not a member yet? Register Sign In |