[eluser]wizzer[/eluser]
I have a form and on it I have an upload script which is taken from Ci documentation. When my form is submitted without a file none of my fields are repopulated, none of the error for the other form fields appear, it only says I have forgot to add a document.
This line Code: $data['error'] = array('error'=>$this->upload->display_errors());
seems to interfering with
Code: $this->form_validation->run()
I dont know what to do, any help would be appreciated.
[eluser]wizzer[/eluser]
i didnt explain well.
i'm using set_value for all the fields, but when I dont have a document in the file upload field, nothing works, no error messge or repopulation.
If i have a file all the validation and stuff works.
any ideas? :-)
[eluser]kierownik[/eluser]
aha maby you can show more code, now we can only guese ofcource
[eluser]wizzer[/eluser]
Code: function do_upload()
{
$this->load->model('user');
$this->load->model('document');
$data['sections'] = $this->user->_getSections();
$data['stats'] = $this->user->_getStats();
$data['error'] = array('error'=>'');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'txt|doc|gif|jpg|png|pdf';
$config['max_size'] = '1024'; //1 meg
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
// SET VALIDATION RULES
$this->form_validation->set_message('is_range', 'Access Level must be a number from 1-5');
$this->form_validation->set_message('is_category', 'Category is a required');
$this->form_validation->set_message('is_section', 'Section is required');
$this->form_validation->set_rules('section[]', 'section', 'is_section');
$this->form_validation->set_rules('lst_category[]', 'category', 'is_category');
$this->form_validation->set_rules('typeofdoc', 'document type', 'required');
$this->form_validation->set_rules('accesslevel', 'access level', 'is_range|required');
$this->form_validation->set_rules('documentname', 'document name','required');
$this->form_validation->set_rules('ownersname', 'owner surname', 'alphanumeric');
$this->form_validation->set_rules('ownerfname', 'owner first name','alphanumeric');
$this->form_validation->set_rules('owneremailaddress','owners email','valid_email');
$this->form_validation->set_rules('project', 'project', 'alphanumeric');
$this->form_validation->set_rules('division', 'division', 'alphanumeric');
$this->form_validation->set_rules('startvalidity', 'start date of validity', 'alphanumeric');
$this->form_validation->set_rules('endvalidity', 'end date of validity', 'alphanumeric');
$this->form_validation->set_rules('docref', 'document reference', 'alphanumeric');
$this->form_validation->set_rules('docnotes', 'document notes', 'alphanumeric');
$this->form_validation->set_rules('startvalidty', 'start date of validity', 'alphanumeric');
$this->form_validation->set_rules('location', 'location', 'alphanumeric');
$this->form_validation->set_rules('startvalidty', 'start date of validity', 'alphanumeric');
$this->form_validation->set_rules('revdate', 'review date', 'alphanumeric');
//get form vars
$section = $this->input->post('section');
$category = $this->input->post('lst_category');
$typeofdoc = $this->input->post('typeofdoc');
$accesslevel = $this->input->post('accesslevel');
$documentname = $this->input->post('documentname');
$ownerfname = $this->input->post('ownerfname');
$ownersname = $this->input->post('ownersname');
$owneremailaddress = $this->input->post('owneremailaddress');
$company = $this->session->userdata('CompanyName');;
$division = $this->input->post('division');
$project = $this->input->post('project');
$location = $this->input->post('location');
$startvalidity = $this->input->post('startvalidity');
$endvalidity = $this->input->post('endvalidity');
$docref = $this->input->post('docref');
$revdate = $this->input->post('revdate');
$docnotes = $this->input->post('docnotes');
$userfile = $this->input->post('userfile');
$UserID = $this->session->userdata('UserID');
//get this users document cap
$documentCap = $this->session->userdata('NoOfDocs');
$companyName= $this->session->userdata('CompanyName');
//get this companies document usage thus far
$usedDocs = $this->user->_getDocumentsUsed($companyName);
// total docs available if any
$totalDocs = $documentCap - $usedDocs;
if($totalDocs < 1)
{
$chkUpload = false;
}
else
{
$chkUpload = true;
}
if ( ! $this->upload->do_upload() || $this->form_validation->run() == false || @$chkUpload == false)
{
if(@$chkUpload == false)
{
$data['caperror'] = "Your document limit has been reached";
}
$data['error'] = array('error'=>$this->upload->display_errors());
$this->load->view('uploaddocument_view', $data);
}
else
{
$data['upload_data'] = $this->upload->data();
$size = $data['upload_data']['file_size'];
$filename = $data['upload_data']['orig_name'];
$this->document->_storeDocument($section,$category,$typeofdoc,$accesslevel,$documentname,$ownerfname,$ownersname,$owneremailaddress,$company,$division,$project,$location,$startvalidity,$endvalidity,$filename,$size,$docref,$revdate,$docnotes);
//$this->load->view('managedocument_view', $data);
redirect('managedocument/index/');
}
}
form works okay ifi have file in file field,
but if user forgets file, none of the set values repopulate form fields and i lose all information, and only 1 error message about the file not being there is displayed.
:-)
[eluser]wizzer[/eluser]
:red: Quote: <input type="text" name="accesslevel" id="accesslevel" value="<?php echo set_value('accesslevel')?>"/>
all my fields look like this
Code: <input type="file" name="userfile" size="20" />
<input type="submit" value="upload"/>
my file field and submit button!
[eluser]kierownik[/eluser]
in the next code I see a difference with the userguide:
Code: if ( ! $this->upload->do_upload() || $this->form_validation->run() == false || @$chkUpload == false)
{
if(@$chkUpload == false)
{
$data['caperror'] = "Your document limit has been reached";
}
$data['error'] = array('error'=>$this->upload->display_errors());
$this->load->view('uploaddocument_view', $data);
}
you set data['error'] again and in the user guide it says $error
maby because off that the errors get overwritten?
[eluser]wizzer[/eluser]
thanks, i tried renaming but the same probelsm exist hahaha
[eluser]kierownik[/eluser]
how does your form in your view file look like?
[eluser]wizzer[/eluser]
my view is too large haha
this is where i output error
Code: <?php echo $error['error'];
echo validation_errors();
echo @$caperror;
?>
and my fields all look like this
Code: <input type="text" name="ownerfname" id="ownerfname" value="<?php echo set_value('ownerfname')?>"/>
:-)
|