views:

53

answers:

3

I have 3 arrays of data that are used to populate some fields on screen. When a user posts the form (unrelated to the data contained in the arrays) I want to display the array data on screen again, but without retrieving it from the database when the page reloads. What's the best way to temporarily store these values?

I was thinking of storing them in the session, is that bad practice? Is there a better way, perhaps passing them as hidden form values?

A: 

Sounds like a perfect use of session. I'd just caution to make sure that you have proper error handling in the database function, because you definitely don't want to mislead a user into thinking the data was saved, when there was actually an error.

marcc
+1  A: 

Generate a set of hidden inputs in the form. Then you can just read them from the post.

CaptnCraig
+1  A: 

Another option could be to serialize the array and save it into a temporary file.

About the question session vs. hidden form fields: The disadvantage of the form fields is that hackers could see it in the HTML source code and misuse it. So you would have to do some extra checks to see if the form fields are in any way valid or not.

The problem with session and serialize is, that the information would be laying around on the server if the user is moving away from the website before he finished the whole process.

And the last thing: You are not writing how large those arrays are. If each of those 3 arrays have several thousand entries then serialize could be a better option than the session and form fields.

Probably sessions is what you need. But the other things should be taken into account too.

Raffael Luthiger