Welcome Guest, Not a member yet? Register   Sign In
Keep upload data in memory on a multiple step form [SOLVED]
#1

[eluser]Ludovic-r[/eluser]
Hi !

I've a little question about keeping in memory the upload data when we have a multiple form, let me explain :

I have a single field to upload my image (linked to a function called do_upload) then when it's uploaded I have a form with several fields (like title, description) linked to another function called add_infos

Until here it's okay when I fill the fields with informations and put "submit" it works very well BUT when I miss a field it shows some errors like "hey you miss the title field" and reload the page and I loose my upload data informations

How can I store in memory the upload data informations and send them into my second function (add_infos) to not lost them when the page is reloaded if there are some errors.

I've tried session but it doesn't seems to work.

IT would be very very apprecited if you could help me because I've tried many things like set_value, session etc and I've read almost the entire posts of this forum. MANY THANKS !

Here's my code :

Code:
function add_infos()
    {    
        
        $this->load->library('form_validation');
        $this->form_validation->set_rules('title', 'title', 'required|xss_clean|encode_php_tags');
        $this->form_validation->set_rules('description', 'description', 'required|trim|xss_clean|encode_php_tags');
        $this->form_validation->set_rules('alt', 'alt', 'required|trim|xss_clean|encode_php_tags');

        
                        if ($this->form_validation->run() == FALSE)
                        {    
                            $this->load->view('upload/upload_part2');
                        }
                        else
                        {store informations in my DB

And the do_upload function :

Code:
function do_upload() { ...my code... then if it's okay :
                            $data = array(
                                'upload_data' => $this->upload->data(),
                                );
                                
                            $this->load->view('upload/upload_part2', $data);    
                        }
}
#2

[eluser]Narkboy[/eluser]
Quick answer - you can't.

HTML is stateless; any request is made without knowledge of any other request.

So - how can we cheat a little?

1) Change to a single form. Far and away the easiest way to do it.
2) Store the data from the first part in a database or text file or anything that can be read by the second part of the script.
3) Use AJAX to either hold the form data and send as one lump, or display the different forms witout actually sending the data to the server.

There are other ways - effectively you must either 1) eliminate the two seperate server calls, or 2) store the data in a more premenant way that php vars.

I would strongly reccommend that you keep it simple. Do you have an unbreakable requirement to have a two-part form? If not, then do it with 1 form.

/B
#3

[eluser]Ludovic-r[/eluser]
Unfortunately, I can't do a single form, it must be a 2 part form Sad So I must know how to keep my upload data in memory to retrieve them if there are some errors in the second form

Thanks for your reply!!
#4

[eluser]WanWizard[/eluser]
The most logical place to store intermediate form data is in the session. Don't use cookie based sessions though, you're probably run out of storage space.
#5

[eluser]Ludovic-r[/eluser]
How can I do this ? I've tried to add upload data in a session according to the userguide but it doesn't work, I must do something wrong ? Any help ?
#6

[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!
#7

[eluser]Vheissu[/eluser]
[quote author="Ludovic-r" date="1288078167"]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![/quote]

Happens to all of us sometimes. I've been a PHP developer for years now and I still have those "should have known" moments every now and them.
#8

[eluser]Narkboy[/eluser]
Yup - we've all lost many many productive days to a problem that eventually gets solve by something so simple you just want to give up coding and life in a cave. Don't stress it!

Smile




Theme © iAndrew 2016 - Forum software by © MyBB