views:

63

answers:

4

I'm working on a web based form builder that uses a mix of Jquery and PHP server side interaction. While the user is building the form I'm trying to determine the best method to store each of one of the form items before all the data is sent to the server. I've looked at the following methods

  1. Javascript arrays
  2. XML document
  3. Send each form item to the server side to be stored in a session
+1  A: 

I used TaffyDB to store data, and it's just wonderfully easy to implement.

Hope this helps you

Marcos Placona
TaffyDB seems like overkill.
Matt Ball
@Bears will eat you And that's because.... It just works nicely, and store whatever information you need. Can't see how this is overkill
Marcos Placona
A: 

A combination of #1 (although I'd use objects, not arrays necessarily) and #3 would seem like a good approach. Storing the data locally in the browser (#1) makes it immediately accessible. Backing that up with session-based server-side storage defends you from the page being refreshed; you can magically restore the page just as it was.

T.J. Crowder
+2  A: 

The good, the bad and the ugly

Depends on your application functionality and requirements, but Javascript would probably be the best way. You can use either arrays or objects or whatever in javascript. It's server independent and it will preserve data over a long period of time as long as client session stays present (browser window doesn't close for whatever reason) but this can be quite easily avoided (check my last paragraph).

Using XML documents would be the worst solution because XML is not as well supported on the client side as you might think.

Server side sessions are good and bad. They are fine if you store intermediate results from time to time, so if client session ends because of whatever reason, user doesn't loose all data. But the problem is that it may as well expire on the server.

If I was you, I'd use Javascript storage and if needed occasionally send JSON serialized results to server and persist them there as well (based on business process storig this data somewhere else than session could be a better solution). I'd do the second part (with sever side combination) only if I would know that user will most probably build forms in multiple stages over a longer period of time and multiple client sessions. but can be used for failure preventions as well. Anyway. Javascript is your best bet with possible server-side interaction.

Preserving data between pages on the client

Be aware that it's also possible to preseve data between pages on the client side. Check sessvars library for this. So even if the page gets refreshed or redirected and then returned all this can be stored on the client side between these events like magic. Marvelous any rather tiny library that made my life several times. And lessened application complexity considerably that would otherwise have to be implemented with something more complex.

Robert Koritnik
+1  A: 
josh3736