CodeIgniter - File upload required validation
Que:
<?php echo form_open_multipart('add'); ?>
<fieldset>
<input type="text" name="name" /><br>
<input type="text" name="code" /><br>
<input type="file" name="userfile" /><br><br>
<input type="submit"value="Add" />
</fieldset>
<?php echo form_close(); ?>
Ans:
I found a solution that works exactly how I want.
I changed
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('code', 'Code', 'trim|required');
$this->form_validation->set_rules('userfile', 'Document', 'required');
To
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('code', 'Code', 'trim|required');
if (empty($_FILES['userfile']['name']))
{
$this->form_validation->set_rules('userfile', 'Document', 'required');
}
}
CodeIgniter - File upload required validation
Reviewed by Anonymous
on
March 03, 2017
Rating:
No comments: