Welcome Guest, Not a member yet? Register   Sign In
Form validation callback with multiple variables
#1

[eluser]Riball[/eluser]
Something that has been bothering me for a while and I couldn't find it in the documentation.

I am working on a CMS that requires authentication. For the login form I would like to use the form validation class since it's awesome.

When authenticating you need a username and a password. So these are my rules.

Code:
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|callback_validate_user');

The validate_user function should get the username and the password, but the way I have set it up now it only gets the password as a variable.

Is it possible to get both variables into the validate_user function.

Thanks

- Mark
#2

[eluser]Riball[/eluser]
Hmm you post something, you find something.

I have now solved this with the following code, but now the question is. Is this THE way to do this?

Code:
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|callback_validate_user['.$this->input->post('username').']');
#3

[eluser]CroNiX[/eluser]
You can just access the input from within the callback function. No need to pass it in to the callback.
#4

[eluser]Riball[/eluser]
Ofcourse, thanks!




Theme © iAndrew 2016 - Forum software by © MyBB