Re: [web2py] Re: Multiple form flash problem.

2011-03-05 Thread Jonathan Lundell
On Mar 5, 2011, at 8:44 AM, annet wrote:
 
 So, in Python you can only simulate a CASE statement using if's? Could
 you provide me with an example?

The first reply here is useful: 
http://stackoverflow.com/questions/594442/choosing-between-different-switch-case-replacements-in-python-dictionary-or-if

Re: [web2py] Re: Multiple form flash problem.

2011-03-02 Thread Jonathan Lundell
On Mar 2, 2011, at 12:27 AM, annet wrote:
 
 Hi Denes,
 
 Thanks for your reply, removing the else: ... solved the problem. I
 followed the if: .. elif: .. else: .. pattern used in the chapter on
 forms and validators in the web2py manual. Why does it work in a
 single form function and why doesn't it work in a multiple form
 function?

While you can put as many forms as you like on the page, the user can submit 
only one at a time. The else clause is invoked when you see a form that hasn't 
been submitted. 

So if the user submits your first form, you'll put something appropriate in 
response.flash, but you'll execute the else cause for the second form and 
clobber it.

 
 
 Since you are not redirecting after an accepts it just comes back to
 the same controller, creating new forms and resetting the
 response.flash messages.
 
 Should I redirect after an accepts? The view has a two column layout,
 the left column contains a search form the right column displays the
 search results.

Don't redirect unless the flow of your logic requires it. But go over your 
logic keeping in mind that at most only one form at a time will be submitted.


 
 
 Hi Jonathan,
 
 Thanks for your reply. I added the response.flash='Fill in form' line
 of code before the first call to accepts, the actual text contains
 more than just the 'Fill in form' directive.
 
 
 Kind regards,
 
 Annet.




Re: [web2py] Re: Multiple form flash problem.

2011-03-01 Thread Jonathan Lundell
On Mar 1, 2011, at 7:04 AM, DenesL wrote:
 
 just remove the
 
else:
response.flash='Fill in form'
 
 parts from your code.
 
 Since you are not redirecting after an accepts it just comes back to
 the same controller, creating new forms and resetting the
 response.flash messages.

This 'else' case isn't very useful anyway; I think of it as a placeholder. If 
you really *do* want a flash message for this case, just set it directly as the 
default response.flash before the first call to accepts.