The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. October 14, 2019, 06:17:22 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: form that maintains state between multiple users or multiple sessions?  (Read 2484 times)
rcjordan
Lifer
*****
Offline Offline

Posts: 882


View Profile
« on: January 21, 2009, 12:18:44 PM »

example: a small group wants to collaborate by selecting items from a form. each item has its own checkbox.

without a DB, what's the K.I.S.S. way to go about this, write the field values to an accompanying text file on close, populate on open?
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #1 on: January 21, 2009, 01:06:15 PM »

multiple users with single dataset?
so like 1 form with 5 people setting checkboxes?
such as a sales In-Out board for example?
and remembers for days with no visits right?

yea file if you have no db. thats really your only option.
Just store the whole form POST as a serialized string.
when page is hit, unserialize and build the form.

OR.

store the whole form, with all you "selected" and "checked" fields set.

the problem is going to be concurrency. 2 people editing at once is gonna lose data of course.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: January 21, 2009, 01:31:47 PM »

If you want to handle concurrency, you could use a COMET methodology (reverse AJAX), where the server updates the clients at will whenever someone makes a change.

FYI - None of what you want to do is trivial, regardless of how you decide to do it.
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: January 21, 2009, 01:46:20 PM »

A text file will do it. You'll want to have your own format for it of course, that you understand. A serialized array is probably your best bet ie.:

$formParams['perk'][0] = true;
$formParams['perk'][1] = false;
$formParams['rc'][0] = true;
$formParams['rc'][1] = false;
$formParams['nutballs'][0] = true;
$formParams['nutballs'][1] = false;
$formParams['vs'][0] = true;
$formParams['vs'][1] = false;
$str = serialize($formParams);

I'd use flock() to grab a lock on the file, then write it (or read it) to emulate a critical section of a multithreaded app. It's advisory - it's not a real lock, so if you have one script that uses flock and another that doesn't you'll get trouble - every script that touches that file MUST use flock or you'll have problems. Also, flock will not work on Windows based servers AFAIK.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
rcjordan
Lifer
*****
Offline Offline

Posts: 882


View Profile
« Reply #4 on: January 21, 2009, 01:57:14 PM »

>and remembers for days with no visits right?

yeah, may be weeks between updates. the form serves as a reminder as to the current state of completion.

thanks, i've got the general direction to follow.

luckily, concurrency isn't a problem in this case. 99% of the work will be by one person with the occasional co-worker asked to access and provide their input by checking/unchecking selections.
Logged
rcjordan
Lifer
*****
Offline Offline

Posts: 882


View Profile
« Reply #5 on: January 23, 2009, 11:39:17 AM »

There's a class already built "Ajax Table Edit" (yep, gotta love the intertubes, perk)
http://www.phpclasses.org/browse/package/3104.html

In the tar/zip, there's a later Advanced example2 that nails it.
http://www.phpclasses.org/browse/file/14338.html
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #6 on: January 23, 2009, 11:45:20 AM »

Nice.

A true hacker never reinvents the wheel.
Logged

hai
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: January 23, 2009, 03:04:42 PM »

Sweetness! Please post your experience RC.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
rcjordan
Lifer
*****
Offline Offline

Posts: 882


View Profile
« Reply #8 on: January 23, 2009, 04:46:32 PM »

>experience

It works as billed straight out of the box.  BTW, who was it here who likes serialized/unserialized arrays? It uses that, too. 

What I like about it is that inside it's still KISS.  Easy to see what it's doing, move fields around, rename, etc.

What it lacks, however, is any further fleshing out. Looks like the developers interest moved on. Niceties like add/delete a row aren't there. That and column sorting would really put it in top order -competing with the heavyweight TableKit (which might seems to have a serious case of the creeping elegance syndrome.
http://www.millstream.com.au/view/code/tablekit/
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!