Welcome Guest, Not a member yet? Register   Sign In
form validation - problem ( script return twice the same validation errors )
#1

[eluser]Krystian[/eluser]
I`ve got problem with validation of my form which contains 5 fields(3 input type="file")


my upload model method

Code:
function do_upload($my_file, $types, $flaque)
{
  
  $this->load->library('upload');
  $config = array(
   'allowed_types' => $types,  //'jpg|jpeg|gif|png',
   'upload_path' => './images/products',//$this->gallery_path,
   'overwrite' => true,
   'max_size' => 4000
  );
  
  $this->upload->initialize($config);

  $this->upload->do_upload($my_file);
  $image_data = $this->upload->data();
  
  if($flaque == 1)
  {
   $config = array(
    'source_image' => $image_data['full_path'],
    'new_image' => './images/products/thumbs',
    //'maintain_ratio' => true,
    'width' => 90,
    'height' => 90
   );
  
   $this->load->library('image_lib', $config);
   $this->image_lib->resize();
  
  }
  
  return $image_data['file_name'];  
}

my controller

Code:
public function upload()
  {
  
    if ($this->input->post('upload'))
    {
    
    $file1 = $this->factory_model->do_upload('device_image', 'jpg|gif|png|jpeg', 1);
    
    $file2 = $this->factory_model->do_upload('device_pdf1', 'pdf', 0);
    
    $file3 = $this->factory_model->do_upload('device_pdf2', 'pdf', 0);
    
    $device = $this->factory_model->add_device(array(
    
           'group_id'     => $this->input->post('hmenu_id'),
           'product_name' => $this->input->post('product_name'),
           'product_desc' => $this->input->post('product_desc'),
           'product_pdf1' => $file2,  
           'product_pdf2' => $file3,
           'product_img'  => $file1
    
          ));
          
    $this->menu_model->update_hmenu_link(array(
             'group_id' => $this->input->post('hmenu_id'),
             'link'     => 'main/device/' . $this->input->post('hmenu_id')
            ));
            
    redirect('dashboard');        
    
   }
  
  }
and if I add validation
Code:
public function upload()
  {
  
  // form validation
  $this->form_validation->set_rules('my_field1', 'my_field1', 'required');
  $this->form_validation->set_rules('my_field2', 'my_field2', 'required');
  $this->form_validation->set_rules('my_file1', 'my_file1', 'required');
  $this->form_validation->set_rules('my_file2', 'my_file2', 'required');
  $this->form_validation->set_rules('my_file3', 'my_file3', 'required');
  
  if($this->form_validation->run())
  {  
  
    if ($this->input->post('upload'))
    {
    
    $file1 = $this->factory_model->do_upload('device_image', 'jpg|gif|png|jpeg', 1);
    
    $file2 = $this->factory_model->do_upload('device_pdf1', 'pdf', 0);
    
    $file3 = $this->factory_model->do_upload('device_pdf2', 'pdf', 0);
    
    $device = $this->factory_model->add_device(array(
    
           'group_id'     => $this->input->post('hmenu_id'),
           'product_name' => $this->input->post('product_name'),
           'product_desc' => $this->input->post('product_desc'),
           'product_pdf1' => $file2,  
           'product_pdf2' => $file3,
           'product_img'  => $file1
    
          ));
          
    $this->menu_model->update_hmenu_link(array(
             'group_id' => $this->input->post('hmenu_id'),
             'link'     => 'main/device/' . $this->input->post('hmenu_id')
            ));
            
    redirect('dashboard');        
    
   }
  }else $this->load->view('dashboard/devices/add_device_form_view', $data);
  
  }
and in view I`m echo-ing form_errors aaaaand I get messeage that each field is required multiple by two. what is going on?




Theme © iAndrew 2016 - Forum software by © MyBB