Hi Annet,

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.



On Mar 1, 8:07 am, annet <annet.verm...@gmail.com> wrote:
> I implemented a one form search function:
>
> def search():
>     rows=[]
>     form=SQLFORM.factory(
>         Field('company',length=54,requires=IS_NOT_EMPTY())
>     if form.accepts(request.vars,session):
>         rows=db(..).select(..)
>         if rows:
>             response.flash='Search result:'
>         else:
>             response.flash='No search result!'
>     elif form.errors:
>         response.flash='Form contains errors'
>     else:
>         response.flash='Fill in form'
>     return dict(form=form,rows=rows)
>
> This code works as expected. Now when I make it a two form search
> function:
>
> def search():
>     rows=[]
>     form1=SQLFORM.factory(
>         Field('company',length=54,requires=IS_NOT_EMPTY())
>      form2=SQLFORM.factory(
>         Field('city',length=54,requires=IS_NOT_EMPTY())
>     if form1.accepts(request.vars,session,formname='form1'):
>         rows=db(..).select(..)
>         if rows:
>             response.flash='Search result:'
>         else:
>             response.flash='No search result!'
>     elif form1.errors:
>         response.flash='Form contains errors'
>     else:
>         response.flash='Fill in form'
>      if form2.accepts(request.vars,session,formname='form2'):
>         rows=db(..).select(..)
>         if rows:
>             response.flash='Search result:'
>         else:
>             response.flash='No search result!'
>     elif form2.errors:
>         response.flash='Form contains errors'
>     else:
>         response.flash='Fill in form'
>     return dict(form1=form1,form2=form2,rows=rows)
>
> ... the flash no longer displays correctly i.e. when the form first
> displays, the flash displays the 'Fill in form' message and after form
> submission and rows containing company objects, instead of displaying
> 'Search result' the flash still displays the 'Fill in form' message.
>
> How should I change the code for the flash to display correctly.
>
> Kind regards,
>
> Annet

Reply via email to