Welcome Guest, Not a member yet? Register   Sign In
passing info to a redirect
#1

[eluser]fchristant[/eluser]
hi there,

I am in doubt on how to best implement some things that I want to pass on to one of my views. I have an image upload form, which looks like this in pseudo-code:

Code:
// set form validation rules here
if ($this->form_validation->run() != false) {
   /// insert image metadata in db, returns id of image: $imageid
   redirect("image/view/$imageid");
} else {
   $this->load->view('image/userupload', $data);
}

This works fine, the "image/view" controller to which I redirect simply expects the image id to be passed via the URI, looks up up data from the db, assigns it to a view, and then renders it. no issues here.

Now, here is what I want to do next. I want to display an "image uploaded successfully" message at the top of the page, but only when the user comes from the upload page, not from a direct image/view/id URL. I do not want to build a seperate success page, since the rest of the page is exactly the same as the page for viewing a single image.

Since I'm doing a redirect, I do not have any control over the page where the user will land, unless I would use a cookie and then detect that on the image view. I don't like that solution though, as that could go wrong in many ways.

Another alternative that I know of is what this forum uses for seach. you see the search form, submit it, you then get redirected to a success page, which then redirects to the result page. It's not terrible, but not the user friendly way that I am looking for.

And yet another alternative would be to pass the status to the URL:

image/view/id/success

That looks messy too, and I still cannot pass the actual message text.

Summarizing, this is what I want for my users:

- user uploads image, gets taken to image result page with success message on top
- user goes to image url directly (image/view/id) and does not see the success message

I've been thinking about not redirecting, instead loading the image view and then passing data to it, but that results in a URL without the ID.

I'm confused in how to achieve what I want...any help?
#2

[eluser]elvix[/eluser]
you want to the session libary's flashdata. it will allow you to set messages for the next (and only next) page load. check the userguide for more.
#3

[eluser]Michael Wales[/eluser]
This is what flashdata was specifically designed to accomplish - check it out in the Session library.
#4

[eluser]fchristant[/eluser]
Thank you gentlemen, that was exactly what I needed.




Theme © iAndrew 2016 - Forum software by © MyBB