Hi,
I want do create a "dynamic form":
(1) On the top of a page there are several questions and
(2) at the end of the page a form should appear.
The content of the form depends on the answers of step (1).
Therefore I tried to insert this new form using ajax.
Result: the form appears, the submit-button works, but the content of
request.vars is always None.
Here is the controller:
def submittest():
script = SCRIPT("""
function lf() {
jQuery.ajax({type: 'POST', url: 'ajax',
success: function(msg) {jQuery('#chk').html(msg); } })};
""")
menu = MENU([['LoadForm',False,'javascript:lf()']])
form = FORM(_name="myform")
if form.accepts(request.vars, session):
result = request.vars.test
else:
result = 'No result'
return dict(menu=menu, script=script, result=result, form=form)
def ajax():
checkboxes = [DIV(INPUT(_type='checkbox',_name='test', _value=v, ),v)
for v in ['a','b','c']]
return str(FORM(INPUT(_type="submit"), *checkboxes,_name='myform'))
And the view:
{{extend 'layout.html'}}
<h1>Submit</h1>
{{=menu}}
{{=script}}
<div id='chk'>{{=form}}</div>
Result: {{=result}}
Maybe the problem is the line form = FORM(_name="myform")
Without this line form.accepts does not work. Two forms, one from the
controller, one created by ajax?
Regards, Martin