[eluser]eedfwChris[/eluser]
I'm a little confused as to how to get the two to work seemlessly together. I have a form with a simple upload field for a CSV file. The callback would be analized to be sure it has the right columns and all that jazz.
My question is, should you use the file upload in a callback? If so, am I doing anything right below?
I'm using the alternative view class.
Code:
/**
* ----------------------------------------------------
* Validate Form
* ----------------------------------------------------
* Validates the RTD search form.
*
*/
function _validate_form()
{
$this->load->library('validation');
/* Set field names */
$fields['name'] = "Site/Community Name";
$fields['state'] = "State";
$fields['file_upload'] = "CSV File";
$this->validation->set_fields($fields);
/* Set validation parameters */
$rules['name'] = "required|max_length[50]";
$rules['state'] = "required|max_length[2]|min_length[2]";
$rules['file_upload'] = "callback__validate_csv";
$this->validation->set_rules($rules);
/* Run validation */
if ($this->validation->run() == FALSE)
{
$this->view->set('validation_error', $this->validation->error_string);
$this->view->part('body', 'rtd/rtd_search_form_view');
}
else
{
echo 'true';
}
}
/**
* ----------------------------------------------------
* Validate CSV
* ----------------------------------------------------
* Validates the uploaded CSV file to ensure that the proper type of CSV is uploaded (or it is a CSV at all)
*
*/
function _validate_csv()
{
$config['upload_path'] = './rtd_tmp/';
$config['allowed_types'] = 'csv';
$this->load->library('upload', $config);
if ($this->upload->do_upload() == FALSE)
{
$this->view->append('validation_error', 'CSV is invalid');
return FALSE;
}
else
{
return TRUE;
}
}