Form can be successfully submitted via ajax and the notification message can be displayed in jquery window ("Your name has been successfully changed!")but when I submit an empty form it doesn't return the message "fail". Could you please check my code and help me to find my mistake.
Controller:
$this->load->library('form_validation');
$this->load->model('my_model');
$this->form_validation->set_rules('name','Name','required|trim|alpha|min_length[3]|xss_clean');
if($this->form_validation->run()) {
$user_id = $this->session->userdata('user_id');
$name = $this->input->post('name');
if ($this->model_users->did_change_name($user_id, $name)) {
$data = array(
'message_ok' => "Your name has been successfully changed!"
);
echo json_encode($data);
} else {
$data = array(
'message' => 'fail'
);
echo json_encode($data);
}
}