Hi!
I have the same problem (twice submission). Here is my little test:
#paste in default.py
#!!! for pure test clean cookies before run!!!
def print_form_keys():
ret=DIV(_class="container")
for i in xrange(5):
frm_k= '_formkey[%s]' % ('frm_id%s/create'%i) #- see html.FORM
ret.append( DIV( frm_k,
OL(*(session[frm_k] or ['None']))
)
)
return dict(r=ret)
def ajx_bug():
form_name='frm_id%s'%request.args(0)
form=SQLFORM.factory(Field('any'), table_name=form_name)
if form.process(session=session).accepted:
response.flash=form.vars.any
return dict(form=form)
#------------ CALL THIS --------------------
def many_ajx_form():
ret={}
for i in xrange(5):
ret['ajx_frm_%s'%i]= \
DIV(
LOAD('utils','ajx_bug.load',
args=[i],
ajax=True,
target='cont_%s'%i
),
_id='cont_%s'%i
)
#----------- ajax print session -----------------
data=dict(
rmt= '/%s/default/print_form_keys.load'%request.application,
trg='print_session'
)
scr=SCRIPT("""
var i=0
var ajx_forms_num=5
$( document ).ajaxComplete(function(e)
{
print_session();
$("form").submit( print_session);
});
function print_session(e)
{
if ((++i)==ajx_forms_num)
{
$.web2py.component("%(rmt)s", "%(trg)s", 0, 1,
$("#%(trg)s"));
}
};
"""%data)
ret['scr']=scr
ret['print']=DIV(_id='print_session')
return ret
Result on local (win7x32, 2.12.1-stable+timestamp.2015.08.07.07.22.06
(Running
on Rocket 1.2.6, Python 2.7.9)):
Many Ajx Form
ajx_frm_0:
Any:
ajx_frm_1:
Any:
ajx_frm_2:
Any:
print:
_formkey[frm_id0/create]
1. *None*
_formkey[frm_id1/create]
1. *None*
_formkey[frm_id2/create]
1. *41f6606c-f149-4382-9216-a35d205a3bd*
As seen, only one ajax form (frm_id2) has a formkey and it works properly!
but other require twice submissions.
It seems, that during ajax-request session locked for write only but not
for read!
Keep in mind that browsers starts next ajax-request before completion of
previous one.
I put some log-code in *FORM.accepts* - it writes session's all formkeys
every FORM.accepts-call to separated files (one call - one file) and I got
the same:
In each file there is only one (but different) formkey! i.e. each
ajax-request process has own version of session.
If set session=None ( *form**.process( session = None )* ) all works
fine!
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.