On Thursday, September 15, 2011 6:29:04 PM UTC-4, Lennon wrote: > > I guess ideally they should be able to submit from either but if that > opens the app up to double submission than the most recent is fine as > long as I have a way to handle the old form gracefully as far as user > experience is concerned. I'm open to ideas. >
If there were two different forms in two different windows, I don't think that would be a double submission risk because each form could still only be submitted once (i.e., in order to submit the second form, the user would still have to manually fill it out and submit it -- there would be no danger that the same form data could be submitted twice). If you want to allow that, you would need to do something to ensure the name of the _formkey stored in the session is unique for each version of the form, so when a new form is created, it doesn't overwrite the value of the _formkey in the session but simply adds a new one. When a new form is created, something like the following is added to the session: _formkey[form_name]='the_form_key' The problem is, by default, form.accepts() creates a standard form name (which is added to the form as a hidden field). Every time the form is created, the name will be the same, so _formkey[form_name] will be the same and will therefore get overwritten in the session. To avoid this, I suppose you could give the form a unique name every time it is created -- that should result in a separate session entry for each version of the form. When a form is submitted, you would then have to check request.vars for the _formname, and if found, assign that as the current form name so it will find the matching session key. Something like: import uuid formname=request.vars._formname or uuid.uuid4() if form.accepts(request,session,formname=formname): etc. Of course, I may be overlooking something, but I think something along those lines would work. Anthony