Welcome Guest, Not a member yet? Register   Sign In
Validation pronlem with standard upload script and forms
#1

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

[eluser]kierownik[/eluser]
I think you should use the set_value option.
http://ellislab.com/codeigniter/user-gui...elper.html
#3

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

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

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

:-)
#6

[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!
#7

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

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

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

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


:-)




Theme © iAndrew 2016 - Forum software by © MyBB