I have a form on my website header where i allow the user to log in with his username/password… then i POST to /signin page and check if the username exists to allow the user to log in.. if there is a problem upon login i output these errors…
i tried using the following code to show a custom error but with no luck
if ($this->form_validation->run() == false){
$this->load->view("login/index", $data);
}else{
$return = $this->_submitLogin();
if ($return == true){
//success
}else{
$this->form_validation->set_message('new_error', 'error goes here');
//error
}
$this->load->view("login/index", $data);
}
how does set_message work and if this is the wrong method, which one allow me to show a custom error in this case?
EDIT :
validation rules:
private $validation_rules = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required|callback__check_valid_username|min_length[6]|max_length[20]|xss_clean'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|min_length[6]|max_length[32]'
),
);
The
set_messagemethod allows you to set your own error messages on the fly. But one thing you should notice is that the key name has to match the function name that it corresponds to.If you need to modify your custom rule, which is
_check_valid_username, you can do so by performset_messagewithin this function:If you want to change the default error message for a specific rule, you can do so by invoking
set_messagewith the first parameter as the rule name and the second parameter as your custom error. E.g., if you want to change therequirederror :If by any chance you need to change the language instead of the error statement itself, create your own
form_validation_lang.phpand put it into the proper language folder inside your system language directory.