One application window opened only

Notice: This thread is very old.
richard
Member | 60
+
0
-

Hi guys.

I need user to be able to open an application (or rather particular presenters) only once. If he opens another instance of such presenter in a new window he should get a warning. How can I do that?

Details: I have a lot of forms (they are setup in DB). User fills them in a wizard – one window is ID specific form (inputs from DB), another is generic (ie. address and so on). It stores values in sessions and redirect everytime as the wizard progresses:
1, /10 (loads a form from DB and redirects to /form/10)
2, /form/10 (ID specific form fillout)
3, /address/10 (some more input)
4, /verify/10 (verifies input)
5, /submit/10 (submits)
In between 2–4 you can go back and forward. This is simplified example.

I guess that design with sessions was not the right one as now, if user opens multiple instances of form id 10 and he wants to fill them all, the session values will get all messed up (you will always have only one set of values for form id 10 in sessions). How can I disable user opening the same presenter instance in new window? Of course he should be able to open /help and /settings etc. in the same time.

Thanks for your suggestions.

Last edited by richard (2012-04-18 04:59)

dfx413
Member | 9
+
0
-

I guess You could simply check if the session record is present and show warning when it is..? For multiple forms at once You could store them in array for example. Maybe I missed something but it seems quite simple.

petr.pavel
Member | 504
+
0
-

I think you could employ some kind of locks that would be locked via JavaScript AJAX call in the background as soon as a page loads. On page exit you would unlock the lock again. This approach however, can be thrown out of balance in case of a network failure (both when locking or unlocking) or if the browser crashes.

The problem is that there is no real method of telling one window from another.

I think a better way would be to forget about limiting the opened windows and find out why submitting the same form from different windows messes up your data.

petr.pavel
Member | 504
+
0
-

Just thinking, couldn't you load all 5 steps into a single page and use tabs to progress through the wizard? You would submit data to the server and save them only at the very end.

Or if you really need to talk to the server in between the steps, you could use AJAX to load the subsequent forms. That way you would only need to worry about not allowing to open the first form/initial page – because the subsequent forms could only be loaded via AJAX from the window that opened the initial page. Again, you would have to use some kind of a lock which would be locked with the first form's submission.

See, the problem with locks is that you have to have some kind of timeout that unlocks them automatically to allow for a recovery from crashed network/browser. But then again, how soon?
If a browser crashes then the user wants to continue immediately – not in an hour. On the other hand, if he goes to lunch and continues with the form when he gets back, he doesn't want to see “You've been logged out” with his data lost. And you may not be able to submit the form for him automatically just before the timeout (e.g. because the act of submission means something in real life).

spidy
Member | 55
+
0
-

You can also add some random string in the URL (like /form-abcdef/10) and store the data in session with the string as key – like this:

function formSubmitted(Form $form) {
	$session = $this->getSession('form');
	$key = $this->getParam('key');
	$session->$key['form-1'] = $form->values;
}
richard
Member | 60
+
0
-

Thanks for suggestions. As a quick fix I have implemented generating random ID number on the beginning of a wizard, saving it into a session and assigning the session to the hidden field. If the value from hidden field does not match the session it redirects to the beginning and shouts. Not very user friendly but it works.