Welcome Guest, Not a member yet? Register   Sign In
Trying upload + input fields at once... no luck
#1

[eluser]Unknown[/eluser]
Dear users,

Im stuck with an form, i want to upload an image but it doesnt work. At the moment i got this:

View:
Code:
<div class="_25">
        <p>
         <label for="textfield2">
          Website afbeelding
         </label>
         &lt;?=form_upload('userfile');?&gt;
         &lt;?=form_error('postcode');?&gt;
        </p>
       </div>

....

      <div class="actions-right">
       &lt;input type="submit" value="Bedrijf toevoegen"&gt;
      </div>

Controller:
Code:
public function add()
{  
  $this->form_validation->set_message('required', '%s is een verplicht veld');
  $this->form_validation->set_message('valid_email', 'Dit is geen geldig E-mail adres');
  $this->form_validation->set_message('max_length', 'Het %s veld mag maximaal %s tekens bevatten');
  $this->form_validation->set_message('min_length', 'Het %s veld moet minimaal %s tekens bevatten');
  
  $this->form_validation->set_error_delimiters('<div>', '</div>');
  
  if ($this->form_validation->run() == FALSE)
  {
   $view["page"] = 'pages/company/addcompanie_view';

   $this->load->view('container', $view);
  
  }
  else
  {
   $data = array();
   foreach(array('naam', 'adres', 'postcode', 'plaats', 'telnr', 'website', 'email_adres', 'status') as $key)
   {
    $data[$key] = $this->input->post($key);
   }
  

   $view["page"] = 'pages/company/companyadded_view';
   $view["company"] = $this->bedrijven->insertCompany($data);

   $this->load->view('container', $view);
  }
}

...

public function _do_upload_image()
{
  $config['upload_path'] = '../../company_images';
     $config['allowed_types'] = 'jpg|jpeg|png';

     $this->load->library('upload', $config);
     if (!$this->upload->do_upload())
     {
         $this->form_validation->set_message('_do_upload_image', $this->upload->display_errors());
         return FALSE;
     }
     else
     {
         $this->filedata = $this->upload->data(); // use $this->filedata for DB insert - like filename or whatever you need
         return TRUE;
     }
    
}

form_validation.php
Code:
array(
    'field' => 'userfile',
    'label' => 'Afbeelding',
    'rules' => 'required|callback__do_upload_image'
   ),

When i fill the form and put submit it turns back to the form without any error... And php error logs says nothing.




Theme © iAndrew 2016 - Forum software by © MyBB