Problem with Form Validation on a page reload [SOLVED] |
[eluser]Ludovic-r[/eluser]
Hi everyone! I try to make a little cms to manage my portfolio with CodeIgniter. So for this I've made a little backend which contains 3 parts (each parts is a different page) : 1st part : upload field (you can upload an image and check if the filesize, extension and so on) 2nd part : image uploaded then you have a small form which contains several fields like 'title' 'description' 'alt' and 3 radio buttons to set 3 different colors picked in the image) and obviously the submit button 3rd part : if there are no errors, everything is stored in the Database and the image appears in the front page with its informations (title, description, color etc) Here is the problem, It works very well but if you miss a field (at part 2) it must show the errors like 'hey you missed the 'title' field' but because the page is reloaded (if the formvalidation return false) I loose my upload informations and I can't go to step 3 Hope you could help me, it will be very very very appreciated! MANY THANKS! Sorry for my english and for my code below (I'm not a perfect developer :p) Here's the code : The upload.php controller : Code: <?php
[eluser]Ludovic-r[/eluser]
The 1st part form : Code: <html>
[eluser]Ludovic-r[/eluser]
The 2nd part form (here's the problem) Code: <html>
[eluser]boldyellow[/eluser]
Not sure I fully understand, but sounds like you are not saving values in the inputs when the form reloads for an error. I'm using form helper which makes it easy to set a value: Code: <?=form_input('teaser', set_value('teaser'); ?> So 'teaser' gets posted and if there's an error, the field is repopulated with the posted info There's more info in the documentation: Scroll down to Re-populating the form
[eluser]Ludovic-r[/eluser]
[quote author="boldyellow" date="1287877147"]Not sure I fully understand, but sounds like you are not saving values in the inputs when the form reloads for an error. I'm using form helper which makes it easy to set a value: Code: <?=form_input('teaser', set_value('teaser'); ?> So 'teaser' gets posted and if there's an error, the field is repopulated with the posted info There's more info in the documentation: Scroll down to Re-populating the form[/quote] First, thanks for your answer (it helps me a lot) I have just a (stupid) question : I've set my values with set_value('...') but what should I do to pass them into my controller (the $this->validation->set_fields($fields); is deprecated), let me explain : I now have this : Code: $data = array( And I would like to retrieve those informations when I reload the page if there are some errors : Code: if ($this->form_validation->run() == FALSE) What should I do ? Create an array and $_POST those informations then pass this array as an attribute ? Thanks so much for your time
[eluser]Ludovic-r[/eluser]
One more thing, if I add this : Code: if ($this->form_validation->run() == FALSE) It works (I mean with no php errors) and reloads the page without the uploads data that I need. I just want to keep the uploads data when I reload the page if there are some errors. Any ideas ?
[eluser]boldyellow[/eluser]
[quote author="Ludovic-r" date="1287905456"] I just want to keep the uploads data when I reload the page if there are some errors. Any ideas ?[/quote] If you mean repopulate the upload form field, won't do that: http://ellislab.com/forums/viewthread/143298/#704468
[eluser]Ludovic-r[/eluser]
Yay I know but how can I store my upload data to keep them when I reload the form page, I've tried session but it doesn't work
[eluser]Ludovic-r[/eluser]
Ok I've solved this after many many tries and coffee : Just store my $data in a session then put this on the DB then if everything is okay destroy the session. That's really easy, shame on me!
[eluser]no-cost lab[/eluser]
Hi there! i have the same problem, would you please post an example for your solution! Thanks in Advance ;-) |
Welcome Guest, Not a member yet? Register Sign In |