每次我更新设置并将输入类型=“文件”留空。 $ this-> form_validation-> run()始终返回false。我甚至没有使用setrules并且需要它。
这是我的代码:
public function update_settings()
{
$this->load->model('bus_owner_model');
$data = $this->bus_owner_model->get_business_data_id_by_row($this->session->userdata('id'));
$this->load->library('form_validation');
$this->form_validation->set_rules('business_name', 'Business Name', 'required|trim|xss_clean');
$this->form_validation->set_rules('type_of_business', 'Type of Business', 'required|trim');
$this->form_validation->set_rules('country', 'Country', 'required|trim');
$this->form_validation->set_rules('address', 'Address', 'required|trim');
$this->form_validation->set_rules('city', 'City', 'required|trim|alpha');
$this->form_validation->set_rules('email_address', 'Email Address', 'required|trim|valid_email');
$this->form_validation->set_rules('contact', 'Contact', 'required|trim|numeric|min_length[7]');
$this->form_validation->set_message('is_unique', 'Your email address is already been taken');
if($this->form_validation->run() == true)
{
$config['upload_path'] = "./_profile_images/";
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['encrypt_name'] = "true";
$this->load->library('upload', $config);
if(!$this->upload->do_upload())
{
$this->bus_settings($this->upload->display_errors());
}else
{
$this->load->model('bus_owner_model');
$file_data = $this->upload->data();
$data = array(
'company_name' => $this->input->post('business_name'),
'profile_img' => $file_data['file_name'],
'type_description' => $this->input->post('type_of_business'),
'country' => $this->input->post('country'),
'address' => $this->input->post('address'),
'state' => $this->input->post('state'),
'city' => $this->input->post('city'),
'email_address_c' => $this->input->post('email_address'),
'contact' => $this->input->post('contact')
);
if($this->bus_owner_model->update_bus($data) == true)
{
redirect('bus_owner/bus_settings');
}else
{
$this->load->model('bus_owner_model');
$this->load->model('user_model');
$data['latlng'] = $this->bus_owner_model->get_latlng();
$data['get_all_business_data_orderby_total_result'] = $this->bus_owner_model->get_all_business_data_orderby_total();
$data['get_all_user_data_orderby_total_result'] = $this->user_model->get_all_user_data_orderby_total();
$data['result_countries'] = $this->bus_owner_model->get_countries();
$data['get_business_data_result'] = $this->bus_owner_model->get_business_data();
$data = array('error' => 'unable to upload files');
$this->load->view('site_header', $data);
$this->load->view('bus_owner_views/left_col_map_single');
$this->load->view('left_col_static', $data);
$this->load->view('bus_owner_views/right_col_settings', $data);
$this->load->view('site_footer');
}
}
}
}
然后它将返回到它的页面,没有任何反复发生。
答案 0 :(得分:0)
我认为您正在尝试上传文件并在其上应用正常的字段验证。这是您尝试验证的错误方式。因为文件字段的行为与普通输入字段不同。请尝试这种方式仅用于文件字段。
public function update_settings()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
redirect('bus_owner/bus_settings');
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}.
有关详细信息,请转到link。