[eluser]brixxster[/eluser]
Hello guys,
I have this function which includes 3 form fields and one file upload field.
I wanted to validate the 3 form fields and check if the file upload field is properly filled and if the file being uploaded does not break any rules that I specify in the configuration.
Now the form field validation looks good but I could not get the upload file field validation to work.
THE CONTROL
Code:
function savePassport(){
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
$this->form_validation->set_rules('passport_num', 'Passport number', 'trim|required');
$this->form_validation->set_rules('passport_issued', 'Passport issued', 'trim|required');
$this->form_validation->set_rules('passport_exp', 'Passport expiration', 'trim|required');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$this->load->library('upload', $config);
if($this->form_validation->run() == FALSE || !$this->upload->do_upload() == TRUE){
$data['error'] = array('error' => $this->upload->display_errors('<span class="error">', '</span>'));
$data['applicant_content'] = '/applicant/updoc/passport';
$data['headTitle']='Upload Passport';
$this->load->view('includes/upload_template_view', $data);
} else {
echo "save";
die();
}
}
THE VIEW
Code:
<?php echo form_open_multipart(site_url() . '/applicant/savePassport');?>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td valign="top">Passport number: </td>
<td><?php echo form_input('passport_num', $this->input->post('passport_num'), 'size="30"');?> <?php echo form_error('passport_num'); ?></td>
</tr>
<tr>
<td valign="top">Issued: </td>
<td><?php echo form_input('passport_issued', $this->input->post('passport_issued'), 'size="30"');?> <?php echo form_error('passport_issued'); ?></td>
</tr>
<tr>
<td valign="top">Expiration:</td>
<td><?php echo form_input('passport_exp', $this->input->post('passport_exp'), 'size="30"');?> <?php echo form_error('passport_exp'); ?></td>
</tr>
<tr>
<td valign="top">Upload passport:</td>
<td><input type="file" name="userfile" /> <?php echo $error['error'];?>
</td>
</tr>
<tr>
<td valign="top"> </td>
<td><input name="acct_id" type="hidden" id="acct_id" value="<?php echo $this->session->userdata['acct_id']; ?>" /><?php echo form_submit('submit', 'Save'); ?></td>
</tr>
</table>
<?php echo form_close();?>
I might be missing something here? Please help...
Thanks in advanced.