1 回答
TA贡献1802条经验 获得超5个赞
您的重定向不会传递 form_error 消息。您需要加载一个视图(您的表单)才能调用 form_error 使用$this->load->view()
尝试这个:
function create_job()
{
// validate each form field
$this->form_validation->set_rules('repair_order', 'Repair Order', 'required');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('phone', 'Phone', 'required');
$this->form_validation->set_rules('vin', 'VIN', 'trim|required');
$this->form_validation->set_rules('year', 'Vehicle Year', 'trim|required|min_length[4]');
$this->form_validation->set_rules('make', 'Vehicle Make', 'required');
$this->form_validation->set_rules('model', 'Vehicle Model', 'required');
$this->form_validation->set_rules('start_date', 'Start Date', 'required');
$this->form_validation->set_rules('promise_date', 'Promise Date', 'required');
$this->form_validation->set_rules('body_hours', 'Body Labor Hours', 'required');
$this->form_validation->set_rules('paint_hours', 'Paint Labor Hours', 'required');
$this->form_validation->set_rules('body_tech', 'Body Technician', 'required');
$this->form_validation->set_rules('paint_tech', 'Paint Technician', 'required');
if($this->form_validation->run())
{
$data = array(
'repair_order' => $this->input->post('repair_order'),
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'address' => $this->input->post('address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zip_code' => $this->input->post('zip_code'),
'phone' => $this->input->post('phone'),
'vin' => $this->input->post('vin'),
'year' => $this->input->post('year'),
'make' => $this->input->post('make'),
'model' => $this->input->post('model'),
'start_date' => $this->input->post('start_date'),
'promise_date' => $this->input->post('promise_date'),
'body_hours' => $this->input->post('body_hours'),
'paint_hours' => $this->input->post('paint_hours'),
'insurance' => $this->input->post('insurance'),
'body_tech' => $this->input->post('body_tech'),
'paint_tech' => $this->input->post('paint_tech')
);
$this->db->insert('jobs', $data);
$this->session->set_flashdata("success", "New job has been successfully created.");
redirect('main');
}
else
{
$this->load->view('yournewjobform');
}
}
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报