![]() |
Validation file input and text input - 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 file input and text input (/showthread.php?tid=53056) Pages:
1
2
|
Validation file input and text input - El Forum - 07-09-2012 [eluser]cyberjunkie[/eluser] Has anyone successfully validated file and text inputs from a multipart form? I tried many solution but nothing seems to work. Please share you experience. Code: function create() //create new post Validation file input and text input - El Forum - 07-10-2012 [eluser]LuckyFella73[/eluser] If you want to validate POST data and uploaded file you use callbacks. Your code code look like that: Code: function create() //create new post It's just a rough example but should show you how you do it basically. Validation file input and text input - El Forum - 07-10-2012 [eluser]boltsabre[/eluser] Sorry, a little off topic from your actual question, this isn't in regards to your actual code, but just a warning about file uploads in general. If you didn't already know, they are VERY risky, and if not done correctly can leave some MASSIVE security holes in your application/website. Make sure you do a google on "php file upload security", there are such things as redrawing images (highly suggested), the set up of you .htaccess file/s and folder structures, creating new random file names, handling code that's been inserted in image meta tags, handling the double extension hack (ie, myimage.php.jpg) and many other things. It's a lot of extra work, but you'll be sorry you didn't if someone deletes your entire website from the server (very easy and possible to do), steals your usernames and passwords, or something else malicious. Validation file input and text input - El Forum - 07-10-2012 [eluser]cyberjunkie[/eluser] @boltsabre, thanks for the warning! I thought that the Codeignter upload library handled all the security issues. @luckyfella73, a callback is a brilliant idea! Thanks, I'll try to implement that. Validation file input and text input - El Forum - 07-10-2012 [eluser]JuanitoDelCielo[/eluser] if ($this->form_validation->run() == FALSE or ! $this->upload->do_upload('image') ) {}else{} Validation file input and text input - El Forum - 07-11-2012 [eluser]LuckyFella73[/eluser] Quote:if ($this->form_validation->run() == FALSE or ! $this->upload->do_upload(‘image’) ) Though that would work as well one advantage of using callback functions when validating a form is that you can easily set appropiate error messages using the build-in functionality (form_validation class). Code: $this->form_validation->set_message('_name_callback_function', $this->upload->display_errors()); Validation file input and text input - El Forum - 07-11-2012 [eluser]JuanitoDelCielo[/eluser] [quote author="LuckyFella73" date="1341996244"] Quote:if ($this->form_validation->run() == FALSE or ! $this->upload->do_upload(‘image’) ) Though that would work as well one advantage of using callback functions when validating a form is that you can easily set appropiate error messages using the build-in functionality (form_validation class). Code: $this->form_validation->set_message('_name_callback_function', $this->upload->display_errors()); True & Sweet, I love your solution! I'll use it from now! Validation file input and text input - El Forum - 07-11-2012 [eluser]cyberjunkie[/eluser] @luckyfella73, have you tested the validation? I have and it doesn't seem to work work. Validation uses $_POST not $_FILE. I think a workaround is hard to implement than just using the file validation. Validation file input and text input - El Forum - 07-11-2012 [eluser]CroNiX[/eluser] You can access $_FILE directly from within a callback rule, and perform the entire upload validation there as well... Validation file input and text input - El Forum - 07-11-2012 [eluser]cyberjunkie[/eluser] for some reason it's not displaying form errors... Code: function _do_upload() function Code: function upload_avatar() |