Welcome Guest, Not a member yet? Register   Sign In
Form validation for title field on a dual file upload form
#1

[eluser]Unknown[/eluser]
Is there an elegant way to include two or more <input type=file> . I have included my code for the controller below.

Currently, this code works aside from the form validation on the title field. I would like to figure out how to include form validation and a file upload.

Code:
<?php echo form_open_multipart('dashboard/do_upload/'. $section);?>
<?php
echo form_label('Upload Large Image here','orig_img');
?>
<input type="file" name="lrgimg" size="20" />
<br>
&lt;?php
echo form_label('Upload Thumbnail Image here','orig_img');
?&gt;
&lt;input type="file" name="smallimg" size="20" /&gt;
&lt;?php
echo "<br />";
echo form_hidden("section", $section );
echo "<br />";
echo form_label('What is the title of the Image','title_label');
echo form_error('title');
$data = array(
      'name'        => 'title',
      'id'          => 'title',
      'maxlength'   => '100',
      'size'        => '50',
      'style'       => 'width:30em',
);
echo "<br />";
echo form_input($data);
?&gt;
<br /><br />

&lt;input type="submit" value="upload" /&gt;

The controller
Code:
$config['upload_path'] = './upload/';
      $config['allowed_types'] = 'gif|jpg|png';
      $config['max_size'] = '10000';
      $config['max_width']  = '1800';
      $config['max_height']  = '1800';
      
      $this->load->library('upload', $config);
      $this->load->library('form_validation');
      
      $error = false;
      if($this->upload->do_upload('smallimg'))
      {
        
         $tmpdata = $this->upload->data();
         $thumb = $tmpdata['file_name'];
        
         if(!$this->upload->do_upload('lrgimg'))
         {
            $error = $this->upload->display_errors();
            $this->view_form($error,$section);
            return;
         }
        
        
         $tmpdata = $this->upload->data();
         $lrg = $tmpdata['file_name'];
         //initialize data for transfer to success page and do final save file from data
         $data['section'] = $section;
         $data['title'] = "Dashboard - Successfully uploadeded file";
        
         $title = $this->input->post('title');
        
         $smalldestination = base_url("upload/" . $thumb);

         $lrgdestination = base_url("upload/" . $lrg );
         $this->home_model->save_temp_photo_data($lrg, $thumb);
         $data['ulimgs'] = $this->home_model->get_uploaded_imgs();
         $this->home_model->add_new_photo($lrgdestination,$smalldestination,$title,$section);
        
         $this->load->view('dashboard/success',$data);
      }
      else
      {
         $error = $this->upload->display_errors();
         $this->view_form($error,$section);
         return;
      }
#2

[eluser]SmokeyJoe[/eluser]
validate your form.
if valid upload your file

Code:
if(!$this->form_validation->run() === FALSE) {
do_upload() etc
look at the manual (form_validation) and put your file upload to a model




Theme © iAndrew 2016 - Forum software by © MyBB