php - Returning false $this->form_validation->run() when there is an empty input type="file" -
every time update settings , leaving input type="file" empty. $this->form_validation->run() returning false. did not use setrules , required it.
here code:
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 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 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'); } } } }
it return it's page , nothing happened.
i think trying upload file , apply normal field validation on it.that's wrong way trying validate.because file field have different behaviour normal input field.try way file field.
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); } }.
for more details goto link.
Comments
Post a Comment