I have this function that displays several fields from two databases.
but I couldn't get it to do the following:
1) the "previous question" button actually causes an error. how come
my session.item_id is always zero when I thought I was passing an
incrementing value session.item_id+1 .
2) when i select a value from the dropdown list get an error saying
that I chose the wrong value
3) i am thinking of collecting the answers in an array so i can check
the answers before storing them as a records in a database. how do i
do that?
i look forward to your suggestions to make this move forward.
def quiz():
item_id =int(request.args(0) or 0)
if item_id == 0:
False).select(orderby='<random>')
# Females = db(db.questionnaire.id>0
).select(orderby='<random>')
print request.args(0), item_id, 'retrieving'
query = db(db.questionnaire.id>0).select(orderby='<random>')
query_t = db(db.questionnaire_fil.id>0).select()
form = SQLFORM.factory(
Field('default', 'text', writable=False, default=query[item_id]
['dialog']),
Field('locale', 'text', writable=False,
default=query_t[int(query[item_id]['dialog_id']-1)]['dialog']),
Field('answer', 'list:string',
requires=IS_IN_SET(query_t[int(query[item_id]['dialog_id'])-1]
['choices'], zero=None, multiple=True)),
_style='width:400px'
)
form[0][-1][1].append(XML(' '))
form[0][-1][1].append(INPUT (_type='button',_value=T('Previous
question'),
_onclick="window.location='%s';"%URL(r=request,args=(item_id-1) or
0)))
if form.accepts(request.vars,session):
if item_id<=len(query):
response.flash= request.vars, item_id, request.args(0)
URL(r=request,args=(item_id+1))
else: URL(r=request, f='quiz_check')
return dict(form=form, item_id=item_id)