CodeIgniter Forums
Validation pronlem with standard upload script and forms - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Validation pronlem with standard upload script and forms (/showthread.php?tid=21583)

Pages: 1 2


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[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.


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]kierownik[/eluser]
I think you should use the set_value option.
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[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? :-)


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]kierownik[/eluser]
aha Smile maby you can show more code, now we can only guese ofcource Big Grin


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[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.

:-)


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]wizzer[/eluser]
:red:
Quote: &lt;input type="text" name="accesslevel" id="accesslevel" value="&lt;?php echo set_value('accesslevel')?&gt;"/&gt;


all my fields look like this


Code:
&lt;input type="file" name="userfile" size="20" /&gt;    
                                                    &lt;input type="submit" value="upload"/&gt;

my file field and submit button!


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[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?


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]wizzer[/eluser]
thanks, i tried renaming but the same probelsm exist hahaha


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]kierownik[/eluser]
how does your form in your view file look like?


Validation pronlem with standard upload script and forms - El Forum - 08-14-2009

[eluser]wizzer[/eluser]
my view is too large haha

this is where i output error
Code:
&lt;?php echo $error['error'];
                                                                                            echo validation_errors();
                                                                                            echo @$caperror;
                                                                                            ?&gt;


and my fields all look like this

Code:
&lt;input type="text" name="ownerfname" id="ownerfname" value="&lt;?php echo set_value('ownerfname')?&gt;"/&gt;


:-)