As it is, your component is not an Ajax component, and it is also not set 
up to trap form submissions via Ajax. So, when you submit the form, it will 
be submitted to the function of the parent page, not to the search_bar 
function. If you want the component to be loaded via Ajax, then set 
ajax=True (and the form will automatically be submitted via Ajax to the 
search_bar function). If you don't want an Ajax component but want the form 
submitted to the search_bar function, then set ajax_trap=True -- that will 
trap the form submission and submit it via Ajax to search_bar. Another 
option would be to explicitly set the form's "action" attribute to submit 
to the search_bar action, but in that case the entire page will reload with 
the response from search_bar, which presumably is not what you want.

Anthony

On Wednesday, May 9, 2012 5:45:08 PM UTC-4, sebastian wrote:
>
> in default.py I have
>
> def search_bar():
>     form = FORM('Search  ',INPUT(_name='qry'))
>     if form.process().accepted:
>         response.flash=''
>         if form.vars.qry:
>             redirect(URL('services', vars={'qry':form.vars.qry}))
>     return form
>
> and in layout.html
>
> {{=LOAD('default','search_bar')}}
>
> but for some reason the form is never accepted...
>
> anh ideas ?
>
> thanks
>
> On Monday, 21 June 2010 17:44:50 UTC+1, mdipierro wrote:
>>
>> 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 <[email protected]> wrote: 
>> > Wow, thanks very much for sharing this trick. I knew it could be easy 
>> > and elegant! :-) 
>> > 
>> > On Jun20, 10:15pm, mdipierro <[email protected]> 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 <[email protected]> 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 <[email protected]> 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