I took up replacing my HTML forms with FORMs. My first use case is a page on which a visitor types in a city and submits the page by clicking a submit button (a form in the left column of the page). The controller function should query the database for leisure clubs in that city and the result should be displayed in a table in the right column of the same page. The function reads like this:
def byplace(): response.functionname=T('Club locator op plaats') form=FORM('Type een plaatsnaam:', INPUT(_type='text',_name='plaatsnaam',requires=IS_NOT_EMPTY ()), INPUT(_type='submit')) if form.accepts(request.vars,session): clubs=db((db.bedrijf.id==db.adres.bedrijf)& (db.bedrijf.id==db.bedrijfbranche.bedrijf)&\ (db.adres.plaatsnaam==request.vars.plaatsnaam)& (db.adres.adressoort==2)&(db.bedrijfbranche.branche==2))\ .select (db.bedrijf.id,db.bedrijf.bedrijfsnaam,db.bedrijf.ranking,db.adres.straatnaam, \ orderby=db.bedrijf.ranking|db.bedrijf.bedrijfsnaam) response.flash='Clubs in' else: response.flash='Formuleer een zoekopdracht' return dict(form=form,clubs=clubs) And the view reads like this: <div id="leftcolumn"> {{=form}} {{include 'functionnavigation.html'}} </div> <!-- leftcolumn --> <div id="mainright"> {{if response.flash:}} <div class="flash"> {{=response.flash}} </div> <!-- flash --> {{pass}} <div id="dt_example"> <table id="example" class="display"> <thead> <tr> <th>bedrijfsnaam</th> <th>straatnaam</th> </tr> </thead> <tbody> {{for club in clubs:}} <tr> <td>{{=A(club.bedrijf.bedrijfsnaam,_href=URL (r=request,f='clubdetails', args=[club.bedrijf.id]),_target="_blank")}} </td> <td>{{=club.adres.straatnaam}}</td> </tr> {{pass}} </tbody> </table> </div> <!-- dt_example --> </div> <!-- mainright --> Exposing the function results in the following error: Traceback (most recent call last): File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 62, in restricted exec ccode in environment File "/Library/Python/2.5/site-packages/web2py/applications/b2c/ controllers/clubs.py", line 60, in <module> File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 55, in <lambda> self._caller=lambda f: f() File "/Library/Python/2.5/site-packages/web2py/applications/b2c/ controllers/clubs.py", line 26, in byplace return dict(form=form,clubs=clubs) UnboundLocalError: local variable 'clubs' referenced before assignment I do understand why it does but I do not know how to solve this problem. I hope one of you does. Best regards, Annet. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---