我有这段代码片段用于在系统中添加患者,但它没有显示任何错误消息。我在视图中有validation_errors()
但仍然没有显示任何内容
这是代码
// Add a new item
public function add()
{
//some form validation rules here
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><i class="icon-exclamation-sign"></i>', '</div>');
$this->form_validation->set_rules('patient_type_id','Patient Type Id','required|trim|xss_clean|integer');
$this->form_validation->set_rules('first_name','First Name','required|trim|xss_clean|max_length[50]');
$this->form_validation->set_rules('middle_name','Middle Name','required|trim|xss_clean|max_length[50]');
$this->form_validation->set_rules('last_name','Last Name','required|trim|xss_clean|max_length[50]');
$this->form_validation->set_rules('gender','Gender','required|trim|xss_clean');
$this->form_validation->set_rules('age','Age','required|trim|xss_clean|max_length[3]|integer');
$this->form_validation->set_rules('address','Address','required|trim|xss_clean');
$this->form_validation->set_rules('status','Status','required|trim|xss_clean');
$this->form_validation->set_rules('contact_number','Contact Number','required|integer|trim|xss_clean');
$this->form_validation->set_rules('email','Email','trim|xss_clean|email|required');
//check if the rules are pass
if($this->form_validation->run()){
//if pass save it to the database
$results = $this->model_nurse_patient->add();
if($results == TRUE){
Console::log('data saved into the database');
$message= "<i class='icon-exclamation-sign'></i>You have successfully added a new patient<br>";
$this->session->set_flashdata('success', $message);
redirect(base_url('nurse/patient'));
}else{
Console::log('data was not saved');
$message= "<i class='icon-exclamation-sign'></i>Failed to add a new patient";
$this->session->set_flashdata('error', $message);
redirect(base_url('nurse/patient'));
}
}else{
//show the form again with errors
Console::log('validation not passed');
$this->create();
}
}
这是$ this-&gt; create()的代码。它只获取页眉,页脚和视图
public function create(){
//just showing the add patient form
Console::log($this->model_nurse_patient->get_all_patient_type());
$create_data['list_rel_status'] = $this->model_nurse_patient->get_all_relationship_status();
$create_data['list_patient_type'] = $this->model_nurse_patient->get_all_patient_type();
$this->nurse_patient_header(array('title'=> 'EHR v1'));
$this->load->view('users/nurse/patient/create',$create_data);
$this->nurse_patient_footer();
}