Advertisement
freddy0512

validasi

Nov 5th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public function do_upload()
  2. {
  3. $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  4. $this->form_validation->set_rules('judul', 'judul', 'required');
  5. $this->form_validation->set_rules('ket', 'ket', 'required');
  6. $this->form_validation->set_rules('tgl', 'tgl', 'required');
  7. $this->form_validation->set_rules('berlaku', 'berlaku', 'required');
  8.  
  9.  
  10. if ($this->form_validation->run() == FALSE)
  11. {
  12. $header = array(
  13. 'title' =>'Welcome to my Website'
  14. );
  15. $content = array(
  16. 'article' =>'Lorem Ipsum Dolor Sit Amet'
  17. );
  18. $data['data_to_load'] = array($header,$content);
  19. $data['tmp_file']='promo/input';
  20. $this->load->view('index',$data);
  21. }
  22.  
  23. else
  24. {
  25.  
  26. $config['upload_path'] = "./gambar/"; //lokasi folder yang akan digunakan untuk menyimpan file
  27. $config['allowed_types'] = 'gif|jpg|png|JPEG'; //extension yang diperbolehkan untuk diupload
  28. $config['file_name'] = url_title($this->input->post('file_upload'));
  29. $this->upload->initialize($config); //meng set config yang sudah di atur
  30. if( !$this->upload->do_upload('file_upload'))
  31. {
  32.  
  33. echo $this->upload->display_errors();
  34.  
  35.  
  36. }
  37. else{
  38. $data = array(
  39. 'gambar'=>$this->upload->file_name,
  40. 'judul' => $this->input->post('judul'),
  41. 'ket' => $this->input->post('ket'),
  42. 'tgl' => $this->input->post('tgl'),
  43. 'masa_berlaku' => $this->input->post('berlaku'),
  44. );
  45.  
  46. //$this->crud->insert($data,'images');
  47.  
  48. $this->promosi_model->addProduct($data);
  49. redirect('promosi');
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement