because keyword appears both in get and in post. You can try: form=SQLFORM.factory( Field('keyword', default=keyword, ) _method="GET")
or form=SQLFORM.factory( Field('keyword', default=request.vars.keyword, )) if form.accepts(request.post_vars, session): response.flash = 'Submitted' really depends on what you need. On Oct 7, 7:50 pm, iiijjjiii <iiijjj...@gmail.com> wrote: > I am trying to provide a default value for an input textbox using > request.vars but am seeing some unusual behaviour. > > Here is my controller: > > def search(): > keyword = '' > if 'keyword' in request.vars: > keyword = request.vars.keyword > form=SQLFORM.factory( > Field('keyword', > default=keyword, > ) > ) > if form.accepts(request.vars, session): > response.flash = 'Submitted' > return dict(form=form) > > The view is basic. > > {{extend 'layout.html'}} > {{=form}} > > I am calling it like this: > > http://www.example.com/demo/default/search?keyword=web2py > > When the page first displays, the input has the default as expected. > However on subsequent submits, the input value is changed to a list > with the keyword appended: > > Submit Input value > 0 web2py > 1 ['web2py', 'web2py']. > 2 ['web2py', "['web2py', 'web2py']"] > ... > > This has something to do with my using the name 'keyword' for both the > field and the default value provided in the URL. If I use a different > name for the field it works normally. > > I see something similar if I replicate the default value in the URL. > For example, this URL > > http://www.example.com/demo/default/search?keyword=web2py&keyword=web2py > > sets the input default to ['web2py', 'web2py'] > > Is this a bug or expected behaviour? > > Is there a better way to permit a flexible default value for a field?