Welcome Guest, Not a member yet? Register   Sign In
Can you validate a condition without associating a field name and callback?
#1

[eluser]hal10001[/eluser]
I want to run a check through a query, but it is associated with multiple fields, not just one (it is a username/password/active user) login check. Can I run this "general" check without using the typical callback approach, and then set a message that says invalid username and password combination? I tried, but it just doesn't return the message.
#2

[eluser]hal10001[/eluser]
Well, the documentation is a little short in this area, but it turns out that your rule name doesn't really need to match your field name. You can do something like this:

Code:
$this->form_validation->set_rules('is_valid_user', '', 'callback__is_valid_user');

The trick is that because is_valid_user is not a form field, you are passing no string value into your callback function. However, whatever post values were sent through are still available in your callback, so you can just use those to do whatever you need.

Code:
function _is_valid_user()
{
    $user_login_id = $this->input->post('user_login_id');
    $user_password = $this->input->post('user_password');
    
    // do something and return true or false;
}
#3

[eluser]TheFuzzy0ne[/eluser]
You don't have to use a validation callback. My auth library has a method called doLogin(). It returns TRUE or FALSE. If it returns FALSE, I can use $this->auth->error_string to get the error string and display it.




Theme © iAndrew 2016 - Forum software by © MyBB