![]() |
How do I validate that a file has been selected. - 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: How do I validate that a file has been selected. (/showthread.php?tid=40968) Pages:
1
2
|
How do I validate that a file has been selected. - El Forum - 04-24-2011 [eluser]DaTran[/eluser] I have this in my controller; as you can see i am using the form validation config file to call all validations. Code: if($this->form_validation->run('anime/add') == TRUE){ How do I use the form validation to "require" the Code: <input type="file" name="image" size="20" /> It keeps saying that there is no image selected. I am also using MY_Form_validation.php to call in custom validations. How do I validate that a file has been selected. - El Forum - 04-25-2011 [eluser]toopay[/eluser] Code: $this->form_validation->set_rules('image', 'Image', 'required'); How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]DaTran[/eluser] That only works for normal input values. It doesn't work if the input type="file" How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]toopay[/eluser] Oh crap, sorry about that. Not really follow this thread carefully. Can you show your full view file? How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]InsiteFX[/eluser] Check the $_FILE array to see if contains your file! InsiteFX How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]toopay[/eluser] InsiteFX, looks like what he want to apply is 'client-side' validation, since he mention... [quote author="DaTran" date="1303690398"]It keeps saying that there is no image selected.[/quote] which mean, the server-side did inspect the input (i'm not aware this too at my first response). I bet, what he need is simple Javascript function on his view files, that prevent submiting the form before user select a file! How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]InsiteFX[/eluser] @toopay, He is using the upload class, so the only way he check a file is through the $_FILE array. Or try the helper function: Code: $this->upload->data() File Uploading Class InsiteFX How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]DaTran[/eluser] I think that is just what I needed however, I have an issue with form_validation when it is empty the MY_Form_validation callback I made will never be called to check if the file is selected or not. So no error message is displayed when the input type="file" is empty. Here is my callback in my MY_Form_validaiton Code: function image($str){ here is more information if it helps (the controller): Code: if($this->input->post()) the config form_validation.php Code: $config = array( How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]InsiteFX[/eluser] Try this: Code: 'anime/add' => array( InsiteFX How do I validate that a file has been selected. - El Forum - 04-27-2011 [eluser]DaTran[/eluser] It didn't work sorry. |