|
| "required", "min_length[x]" are default validation rules from the Code Igniter framework. | |
| callback__password_check is a custom validation function to accomodate your own need. | |
| $rules should be filled with your preferred validation rules. | |
| $fields should be filled with field name what should come up on validation error message. | |
| $this->validation->set_error_delimiters will enclose the validation error message with your custom css. | |
| the underspace symbol (_) in front of function name means the function is private and cannot be called from the URL address alone. | |
| the callback function always has to be in "callback_" format with underspace symbol at the end. |
/* Check into database whether the input for current password is valid or not */ function _password_check($current_password, $adminid) { $result = $this->oAdmin->check_password($current_password, $adminid); if($result->num_rows() == 0) { $this->validation->set_message('_password_check', 'Current password is invalid'); return FALSE; } else { return TRUE; } }
A couple of things to note:
| $this->oAdmin->check_password is a model function to check the database to ensure whether the current user password is valid or not. | |
| $this->validation->set_message will set your error message when the validation fails. |
function change_password() { $this->_set_validation_password($this->session->userdata('adminid')); if($this->validation->run() == FALSE) { // do something if the validation doesn't pass } else { // do something if the validation passes } }
A couple of things to note:
| $this->_set_validation_password will set the following validation function as default. | |
| $this->validation->run() will execute the form validation function set as above. |

How validation works and its callback function in Code Igniter
Recent comments