所有数据已经插入到数据库中,但是字段city_case没有插入,如果我用act_id这样的另一个字段替换这个字段,它插入正确,我确定在view / add.php这个字段中的问题
in controllers / cases.php
function add(){
$data['fields_clients'] = $this->custom_field_model->get_custom_fields(1);
$data['fields'] = $this->custom_field_model->get_custom_fields(2);
$data['clients'] = $this->cases_model->get_all_clients();
$data['stages'] = $this->case_stage_model->get_all();
$data['acts'] = $this->cases_model->get_all_acts();
$data['courts'] = $this->cases_model->get_all_courts();
$data['locations'] = $this->cases_model->get_all_locations();
$data['case_categories'] = $this->cases_model->get_all_case_categories();
$data['court_categories']= $this->cases_model->get_all_court_categories();
$data['city'] = $this->cases_model->get_name_city();
//$data['employee'] = $this->cases_model->get_name_employee();
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
$this->load->library('form_validation');
$this->form_validation->set_message('required', lang('custom_required'));
$this->form_validation->set_rules('title', 'lang:title', 'required');
$this->form_validation->set_rules('client_id', 'Client', '');
$this->form_validation->set_rules('case_no', 'Case No', ''); //trim|required|is_unique[cases.case_no]
$this->form_validation->set_rules('location_id', 'Location', '');
$this->form_validation->set_rules('case_stage_id', 'Case Stage', '');
$this->form_validation->set_rules('court_id', 'Court', '');
$this->form_validation->set_rules('court_category_id', 'Court Category', '');
$this->form_validation->set_rules('case_category_id', 'Case Category', '');
$this->form_validation->set_rules('act_id', 'Act', '');
$this->form_validation->set_rules('start_date', 'Filing Date', '');
$this->form_validation->set_rules('description', 'Description', '');
$this->form_validation->set_rules('city_case', 'city case', '');
$this->form_validation->set_rules('fees', 'Fees', '');
$this->form_validation->set_rules('o_lawyer', 'Opposite Lawyer', '');
$this->form_validation->set_rules('hearing_date', 'Description', '');
if ($this->form_validation->run()==true)
{
$save['title'] = $this->input->post('title');
$save['case_no'] = $this->input->post('case_no');
$save['client_id'] = $this->input->post('client_id');
$save['location_id'] = $this->input->post('location_id');
$save['court_id'] = $this->input->post('court_id');
$save['court_category_id'] = $this->input->post('court_category_id');
$save['case_stage_id'] = $this->input->post('case_stage_id');
$save['case_category_id'] = json_encode($this->input->post('case_category_id'));
$save['act_id'] = json_encode($this->input->post('act_id'));
$save['description'] = $this->input->post('description');
$save['start_date'] = $this->input->post('start_date');
$save['hearing_date'] = $this->input->post('hearing_date');
$save['o_lawyer'] = $this->input->post('o_lawyer');
$save['fees'] = $this->input->post('fees');
$save['city_case'] = json_encode($this->input->post('city_case'));
$p_key = $this->cases_model->save($save);
$reply = $this->input->post('reply');
if(!empty($reply)){
foreach($this->input->post('reply') as $key => $val) {
$save_fields[] = array(
'custom_field_id'=> $key,
'reply'=> $val,
'table_id'=> $p_key,
'form'=> 2,
);
}
$this->custom_field_model->save_answer($save_fields);
}
$this->session->set_flashdata('message', lang('case_created'));
redirect('admin/cases');
}
}
$data['page_title'] = lang('add') . lang('case');
$data['body'] = 'case/add';
$this->load->view('template/main', $data);
}
models / cases_model.php
function get_name_city ()
{
$query = $this->db->get ('user_role');
return $query->result();
}
this is code I sure the problem in it
<select name="city_case[]" class="chzn col-md-12" multiple="multiple" >
<option value="">--<?php echo lang('select_city')?>--</option> <?php foreach($city as $new) { $sel = ""; if(set_select('city_case', $new->id)) $sel = "selected='selected'"; echo '<option value="'.$new->id.'" '.$sel.'>'.$new->name.'</option>'; }?>
</select>
I replace it with this code , it work well
<input type="text" name="city_case" class="form-control" value="<?php echo set_value('city_case'); ?>">
,你能帮助我吗?
答案 0 :(得分:0)
将此行更改为
$save['city_case'] = json_encode($this->input->post('city_case'));
要
$save['city_case'] = json_encode($this->input->post('city_case[]'));