[eluser]garymardell[/eluser]
I assume you have something like this a callback to do the upload.
Code:
function _upload_file()
{
// try to upload the form return error if failed.
$config['upload_path'] = './public/uploads/sermons/';
$config['allowed_types'] = 'mp3|jpg|jpeg';
$config['max_size'] = '2000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload("sermon"))
{
$this->form_validation->set_message('_upload_file', 'The file could not be uploaded.');
return false;
}
else
{
return true;
}
}
Now in the callback you could add a check to see if the other field was filled in.
Code:
function _upload_file()
{
if(!empty($this->input->post("field_name")))
{
return true;
}
// try to upload the form return error if failed.
$config['upload_path'] = './public/uploads/sermons/';
$config['allowed_types'] = 'mp3|jpg|jpeg';
$config['max_size'] = '2000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload("sermon"))
{
$this->form_validation->set_message('_upload_file', 'The file could not be uploaded.');
return false;
}
else
{
return true;
}
}
This will check if the other field is filled in and if it is then it will return true, so the upload will not be done and for the validation purposes will appear successful (basically skipped).