i want to do this: user selects some of the questions (checkboxes) and 
saves them a test (SQLFORM). it doesn't matter how to do this. with or 
without form, redirects or in one page. 
i was using q's to retrieve selected checboxes,

i did it with jquery. my way:

page1: test.html

select page. i retrieve selected questions with jquery and generate a link 
like this: /create_test?questions=1,2,3,4,9,10

page2: create_test.html

save test with questions, gives name with SQLFORM.

it works. 

my db:

db.define_table('questions',Field('question_image').......)


db.define_table('tests',Field('name'),Field('questions').....)


i didn't use list:reference. i store question ids as string seperated with 
comma.


20 Aralık 2015 Pazar 21:16:24 UTC+2 tarihinde Anthony yazdı:
>
> On Sunday, December 20, 2015 at 6:39:45 AM UTC-5, xmarx wrote:
>>
>>
>> def test2():
>>     if request.vars and request.vars.q:
>>         selected_questions=request.vars.q
>>         form=SQLFORM(db.test)
>>         if form.process().accepted:
>>             session.flash='Test added!'
>>             redirect(URL('test3'))
>>         else:
>>             response.flash='form has an error.'
>>     return locals()
>>
>> test1.html display form. if i submit it redirects with post_vars to 
>> test2.html. but test2.html says "form has an error" when loading page. i 
>> mean i didn't fill second (SQLFORM) form and i didn't submit it.
>>
>
> You only have two conditions: (1) the form is accepted, (2) the "form has 
> an error" message is displayed. The form is only accepted after it has been 
> submitted and passed validation, so in all other cases (e.g., when the form 
> is first created), you will get the error message. If you look at the book 
> examples, you will see there are three conditions, with an error message 
> displayed only via an "elif form.errors" condition. 
>
> if i fill second form and submit it, it didn't test3.html. nothing happend 
>> actually.
>>
>
> All of your form logic is inside an "if request.vars.q" condition. 
> However, "q" is in request.vars only upon the initial redirect from test1, 
> which results in the blank test2 form being created. When you then submit 
> the test2 form, there is no longer a "q" variable in request.vars, so all 
> of the form code in test2 is skipped.
>
> Hard to say what the best approach would be without knowing what you're 
> doing with "q" (i.e., does it need to persist past the initial redirect?), 
> but you'll need some logic to ensure the test2 form code gets run once its 
> form is submitted.
>
> Anthony
>

-- 
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.

Reply via email to