[eluser]feri_soft[/eluser]
I have two validation issues. First one i have a login system and i wanted to create my callback for the validation to see if the following data is correct and the users logs in
So here is something:
Code:
function login()
{
$this->validation->set_message('check_login', 'sdfdfsdf');
$rules['username'] = "trim|required|callback_check_login|xss_clean";
$rules['password'] = "trim|required|xss_clean";
$rules['remember'] = "numeric";
$this->validation->set_rules($rules);
$fields['username'] = 'asda';
$fields['password'] = 'sdasd';
$fields['remember'] = 'asdasd';
$this->validation->set_fields($fields);
if ($this->validation->run() == false)
{
$this->load->view('login');
}else{
$this->load->view('profile');
}
}
And i have created a simple callback to check the login:
Code:
function _check_login($username, $password, $remember){
if($this->user_model->login($username, $password, $remember)){
return true;
}else{
return false;
}
}
Obviously this doesnt work as the validation requires only one parameter to work. I could create something else like checking the login in the else clause and if error occurs display the login form with an array data containing something like: '1' => 'No such user', '2' => 'Wrong pass' etc...but i thing this is kind of a double work first create erros array in validation and then create 2nd errors array for login check. Makes no sense. Isnt there a way working with the Ci itself with no other modifications to make my idea working and use callback with multiple attributes. Like the matches and min_lenght / max_lenght funcs.
And i have another very simillar problem tried to create telephone check to see if a user has entered a valid phone or valid GSM and if none of the two is entered display error. So i wrote something like:
Code:
function _phoneorgsm(){
if(!empty($_POST['phone']) && is_numeric($_POST['phone'])){
return true;
}elseif(!empty($_POST['gsm']) && is_numeric($_POST['gsm'])){
return true;
}else{
return false;
}
}
but for some reasons it doesnt work just displays me the page with all other errors and not this one. I suppose the same will happen if i try this on the login so i didnt. Here is the function:
Code:
$this->validation->set_message('phoneorgsm', 'asdasdasdasd');
$rules['phone'] = "trim|callback_phoneorgsm";
$rules['gsm'] = "trim|callback_phoneorgsm";
etc....
Any ideas i need something very very urgently because i am on a hurry with this one. Thanks a lot !