![]() |
Form validation and file upload - 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: Form validation and file upload (/showthread.php?tid=51315) |
Form validation and file upload - El Forum - 04-29-2012 [eluser]someone ![]() Hello, I would like to create some upload script where the user will enter title and description of file which will be uploaded, but I have problem. Controller: Code: // some form validation variables This is not finished, because I don't know how to correctly open form - with form_open() or form_open_multipart(), to get all data checked for validation and after that to insert into database. What do I have to do? Thanks in advance! :-) Form validation and file upload - El Forum - 04-29-2012 [eluser]FightingMan[/eluser] Maybe you can see the userguid. you want to use form and form_validation helper,at first you must load them. Also I autoload them,you can set in /application/config/autoload.php,except the file_upload library,in fact you can do it if you must use it many times. you should see here:http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html Good Luck with you! ![]() Form validation and file upload - El Forum - 04-29-2012 [eluser]someone ![]() Ok, I find soulution: Code: // some form validation variables But now I have new question. How to false form if there is error when uploading file? Thanks! :-) Form validation and file upload - El Forum - 04-29-2012 [eluser]Stefan Hueg[/eluser] Quote:But now I have new question. How to false form if there is error when uploading file? Put your upload-code into a seperate function like file_upload(), put this callback -function in as a rule (callback_file_upload) and let that upload function return FALSE on error or TRUE if no file was selected or upload has finished successfully. Read the specific section in the documentation: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks Form validation and file upload - El Forum - 04-30-2012 [eluser]someone ![]() It's good idea, but I don't want to use callback function if this isn't necessary. Is there any other solution like this example: Code: if ($uploaderror == TRUE) Form validation and file upload - El Forum - 04-30-2012 [eluser]Stefan Hueg[/eluser] Of course you could do something like this Code: if ($this->form_validation->run() && $uploaderror == FALSE) //everything is fine but this looks like a hack and it's better to stay with the form validation class. Form validation and file upload - El Forum - 04-30-2012 [eluser]someone ![]() Ok. Is it possible to save field's values and then if there is an error (I'm using flashdata+redirect) display them? Form validation and file upload - El Forum - 04-30-2012 [eluser]Stefan Hueg[/eluser] Do you need the redirect? If not: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#repopulatingform Else you could store them in your session data and repopulate it by yourself, but again you are bypassing the form validation class which makes it obsolete ![]() Form validation and file upload - El Forum - 04-30-2012 [eluser]someone ![]() This is true but I think (for your first solution) it's not good to do very important (save uploaded file, resize image, load model and insert data in database) things with callback function. Any other idea? Form validation and file upload - El Forum - 04-30-2012 [eluser]someone ![]() I get the solution: Code: // some form validation variables Thanks for help anyway! :-) |