Welcome Guest, Not a member yet? Register   Sign In
Login script: validating with own callback in library.
#10

[eluser]Pascal Kriete[/eluser]
Assuming the rule is set on the password field (the last field you set at any rate, so that all values have been trimmed):
Code:
$this->CI->form_validation->set_rules('password', 'Password', 'trim|required|validate_login[email]');

The first parameter of a callback is always that field's value - the second parameter is the contents inside the brackets. So here I'm giving it "email" to pass along the name of the email field. You could even extend it to say [password|email] and then explode on the pipe to extract the field names. But if we know that the callback is on the password field, that's not really needed.

And then the callback becomes:
Code:
function validate_login($password, $email_field = '')
{
    $email = $this->CI->input->post($email_field);

Alternatively you could move grabbing the post values to the auth library and just use the extended form validation library to call that function. Then setup a setter in the auth library (something like set_credential_fields) that stores the field names in an instance variable, and call that before running the validation.

Lots of options here Wink .


Messages In This Thread
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 05:59 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 06:14 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 07:29 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 08:13 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 08:41 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 09:56 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 10:08 AM
Login script: validating with own callback in library. - by El Forum - 09-07-2009, 10:11 AM
Login script: validating with own callback in library. - by El Forum - 09-08-2009, 05:42 AM
Login script: validating with own callback in library. - by El Forum - 09-08-2009, 09:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB