You can also do

if response.flash: response.headers['web2py-component-
flash']=response.flash

before return and you can keep using response.flash and session.flash
as usual.

On Jun 21, 10:10 am, Iceberg <iceb...@21cn.com> wrote:
> Wow, thanks very much for sharing this trick. I knew it could be easy
> and elegant! :-)
>
> On Jun20, 10:15pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Because the form is submitted and returned via ajax the usual
> > mechanism does not work but you can do:
>
> > def form():
> >     form=SQLFORM.factory(
> >        Field('name', requires=IS_NOT_EMPTY()))
> >     if form.accepts(request.vars, session):
> >         response.headers['web2py-component-flash'] = 'form accepted'
> >     else:
> >         response.headers['web2py-component-flash'] = 'form has errors'
> >     return form
>
> > I.E. place the flash in a HTTP header and web2py will read it and
> > place it in the flash box.
>
> > On Jun 19, 11:23 am, Julius Minka <j...@minka.sk> wrote:
>
> > > def form():
> > >     form=SQLFORM.factory(
> > >        Field('name', requires=IS_NOT_EMPTY()))
> > >     if form.accepts(request.vars, session):
> > >         response.flash = 'form accepted'
> > >     else:
> > >         response.flash = 'form has errors'
> > >     return form
>
> > > Flash is not displayed in this place, elsewhere is working. Why?
> > > Or, how let user know about the result of form submission?
>
> > > V Sobota, 19. jún 2010 o 00:41 -0700, mdipierro napísal(a):
>
> > > > Just do
>
> > > > def contact():
> > > >      form=SQLFORM.factory(....)
> > > >      if form.accepts(....)
> > > >      return form # not dict(form=form)
>
> > > > and in layout.html
>
> > > > {{=LOAD('default','contact')}}
>
> > > > On Jun 18, 11:26 am, Julius Minka <j...@minka.sk> wrote:
> > > > > I need a contact form (name, address,...) on every page of a web site.
> > > > > Thinking about putting the form into layout.html and use some Ajax to
> > > > > send entered values to be processed by a controller. I would like to
> > > > > avoid page reload on form submission.
>
> > > > > I found 2 possible solutions in the archive:
> > > > > 1.http://groups.google.com/group/web2py/browse_thread/thread/f162f35e4a...
> > > > > Is this incomplete? How process function is called?
>
> > > > > 2.http://groups.google.com/group/web2py/browse_thread/thread/82fad17e26...
> > > > > I ran application mentioned in the thread. This is probably close, but
> > > > > complicated.
>
> > > > > What is good and simple approach to this issue? I do not have much
> > > > > experience with Ajax.
>
> > > > > Thanks
> > > > > Julius

Reply via email to