Validation problem for form_upload - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Validation problem for form_upload (/showthread.php?tid=5035) |
Validation problem for form_upload - El Forum - 01-02-2008 [eluser]cinewbie81[/eluser] Hi guys, I have this on my form: Code: form_upload('csvFile', 'csvFile') and here's my form validation Code: $rules['csvFile'] = "required"; csvFile's rules has been set to 'required' because i want to make sure that users actually browse for a file. Anyway, the validation error : "The CSV files field must have a value" is always display even though i have already browse for the file. Anyone ? Thanks in advance and Happy New Year 2008. Validation problem for form_upload - El Forum - 01-02-2008 [eluser]Sawariya[/eluser] if (!$this->upload->do_upload('csvFile')) { return $this->upload->display_errors(); } Validation problem for form_upload - El Forum - 01-02-2008 [eluser]xwero[/eluser] As Sawariya points out the upload validation is not present in the validation library. This is because the validation library only searches in the $_POST global where the upload is located in the $_FILES global. Validation problem for form_upload - El Forum - 01-02-2008 [eluser]cinewbie81[/eluser] Let's say i have a form_input and a form_upload component . How can I do the verification for both component together ?? My code again: Code: form_upload('csvFile', 'csvFile') Code: $rules['csvFile'] = "required"; Validation problem for form_upload - El Forum - 01-02-2008 [eluser]xwero[/eluser] Code: // checking for errors + building error string Validation problem for form_upload - El Forum - 01-02-2008 [eluser]cinewbie81[/eluser] Hi, the code died at this statement: Code: if (!$this->upload->do_upload(’csvFile’)) Error: Severity: Notice Message: Undefined property: Student::$upload Any idea ? Validation problem for form_upload - El Forum - 01-02-2008 [eluser]Sawariya[/eluser] you have to call this library $this->load->library('upload', $config); Validation problem for form_upload - El Forum - 01-02-2008 [eluser]Sawariya[/eluser] function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $arr= array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $arr); } else { $data = array('upload_data' => $this->upload->data()); $this->load->view('upload_success', $data); } } |