Hi,
I have some undesired behavior in my app that I was able to resolve, but I
would like to understand what goes wrong.
I could easily reproduce the problem with a simple test-application,
containing two pages and two forms (I'm skipping the boilerplate code that
is created when making a new application):
####menu.py####
response.menu = [
(T('Home'), False, URL('default', 'index'), []),
(T('Secondpage'), False, URL('default', 'secondpage'), []),
]
####controller####
def index():
form = SQLFORM.grid(db.contact, create=True, user_signature=False, )
return dict(form=form)
def secondpage():
form = SQLFORM.grid(db.activity, create=True, user_signature=False, )
return dict(form=form)
####index.html####
{{extend 'layout.html'}}
<h1>Index page</h1>
{{=form}}
####secondpage.html####
{{extend 'layout.html'}}
<h1>Welcome to the 2nd page</h1>
{{=form}}
####db.py####
contact = db.define_table('contact',
Field('first_name', 'string'),
Field('last_name', 'string'),
)
activity = db.define_table('activity',
Field('what_you_plan_to_do', 'string'),
)
The problem occurs as follows:
* I go to the index page
* I press the add button opening up the contacts form (which I don't fill
in at this point)
* In the menu I now press the link to the secondpage
* When the secondpage is loaded I press the browser's back-button
* Now I see the contacts form again which I fill in
* When I now press the Submit button, I am redirected to the secondpage as
opposed to staying on the index page, which is not the desired outcome.
I could resolve this by giving the forms a formname, but I would like to
understand why this behavior occurs.
In this specific example the undesired behavior is not critical, but it was
really a problem in my app as the redirect went to a .load page that did
not contain any css styling.
####Updated controller resolving the problem####
def index():
form = SQLFORM.grid(db.contact, create=True, user_signature=False,
formname='contact')
return dict(form=form)
def secondpage():
form = SQLFORM.grid(db.activity, create=True, user_signature=False,
formname='activity')
return dict(form=form)
####web2py version info####
2.8.2-stable+timestamp.2013.11.28.13.54.07
(Running on Rocket 1.2.6, Python 2.7.5)
Thanks!
--
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.