php - Codeigniter image upload with text field validation -


in codeigniter have add_main_products function upload image database , before want validate text field <input type="text" name="product_name"> . how do inside add_main_products() function

   function add_main_products(){          $config['upload_path'] = 'application/views/uploads/';                     $config['allowed_types'] = 'gif|jpg|png|jpeg';               $this->load->library('upload', $config);              if (!$this->upload->do_upload('userfile')) {              $error = array('error' => $this->upload->display_errors());             $this->load->view('admin/admin_add_mainproduct', $error);          } else {              $this->mod_products->add_main_product($this->upload->data());             $data = array('upload_data' => $this->upload->data());             $this->load->view('admin/admin_add_mainproduct', $data);  }          } 

you can this

     function add_main_products(){          $this->form_validation->set_rules('product_name', 'product name', 'required');          if ($this->form_validation->run() == false){             $this->load->view('admin/admin_add_mainproduct');         }            else{               $config['upload_path'] = 'application/views/uploads/';                          $config['allowed_types'] = 'gif|jpg|png|jpeg';                          $this->load->library('upload', $config);               if (! $this->upload->do_upload()){                 $error['error'] = array('error' => $this->upload->display_errors());                 $this->load->view('admin/admin_add_mainproduct', $error);                 return false;                 }                 $this->mod_products->add_main_product($this->upload->data());                $data = array('upload_data' => $this->upload->data());                $this->load->view('admin/admin_add_mainproduct', $data);          }  } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -