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