Hope you guys can give me a hand here. I have two central functions in my
controller: index() and resultsDisplay()
In index() the user enters a string into a form and it is assigned to
session.var.a
session.var.a is passed to resultsDisplay() and it is processed. In the
resultsDisplay() view, I want the form from index() to be shown with the
user's string in it. I also will have a number of alternative suggestions
for the user. What I want is that if the user enters another term in the
form on the results page, or if the user clicks one of the supplied
suggestions, the resultsDisplay() function will restart, except that
instead of session.var.a being the form data from the index(), it will be
whatever the new value is. A great example of this is Google. If you type a
query in the main bar it gives you results. You notice that you've spelt
the query incorrectly. Google offers a suggestion, or the user has the
option of re-typing the query in the box and getting a new set of results.
How would I do this? Also, on a side note, how do I give the radio buttons
in my form a default value?
*def index():*
form = SQLFORM.factory(
Field('field_1','string', widget=SQLFORM.widgets.string.widget,
requires=IS_NOT_EMPTY()),
Field('field_2',requires=IS_IN_SET(('Yes','No')), widget=SQLFORM.
widgets.radio.widget),
submit_button='Go!')
if form.process().accepted:
session.term=request.vars.field_1
session.aggregate=request.vars.field_2
redirect(URL('resultsDisplay'))
else:
response.flash = 'please fill the form'
return dict(form=form)
*def resultsDisplay():*
__function_1(session.term)
do some processing
__function_2(session.term)
do some processing
__function_3(session.term)
return locals()
*index.html:*
{{=form.custom.begin}}
<div id="textBar">{{=form.custom.widget.field_1}}<br />
{{=form.custom.submit}}</div>
<br />
Choice:
<div>{{=form.custom.widget.field_2}}</div>
{{=form.custom.end}}
*resultsDisplay.html:*
*
*
#I want to put the form from index.html here
{{=DisplayResults_as per resultsDisplay function}}
#I want to put suggestions that, when clicked, will reload this page with
new result set.
--