Form validation and file upload |
[eluser]someone [/eluser]
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! :-)
[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-gui...ading.html http://ellislab.com/codeigniter/user-gui...elper.html Good Luck with you!
[eluser]someone [/eluser]
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! :-)
[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-gui...#callbacks
[eluser]someone [/eluser]
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)
[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.
[eluser]someone [/eluser]
Ok. Is it possible to save field's values and then if there is an error (I'm using flashdata+redirect) display them?
[eluser]Stefan Hueg[/eluser]
Do you need the redirect? If not: http://ellislab.com/codeigniter/user-gui...latingform 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
[eluser]someone [/eluser]
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?
[eluser]someone [/eluser]
I get the solution: Code: // some form validation variables Thanks for help anyway! :-) |
Welcome Guest, Not a member yet? Register Sign In |