You have a few problems, fixed below hopefully

def index():
    form = FORM(TABLE(TR('Field:','',
                         SELECT(
                             OPTION('title', _value = 1),
                             OPTION('affiliation', _value = 2),
                             OPTION('country', _value = 3),
                             OPTION('year', _value = 4),
                             OPTION('research_field', _value = 5),
                             OPTION('journal', _value= 6),
                             OPTION('keywords', _value = 7),
                             OPTION('author',_value = 8),
                             OPTION('source', _value 8), value =
1,_name='field')),
                      TR('Operator:', '',
                         SELECT(
                             OPTION('equals', _value= 1),
                             OPTION('starts with', _value = 2),
                             OPTION('contains', _value = 3), value
=1,_name='operator')),
                       TR('Value:', '',
                         INPUT(_name = 'searchfor')),
                      TR('', '', INPUT(_type = 'submit' ))))
    if form.accepts(request.vars, session):
        redirect(URL(r=request, f='list_records',vars=request.vars))
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'Please select the field, operator and type
in the search field'
    return dict(form=form)

And
def list_records():
    db.sarua.id.represent = lambda value: UL(
        LI(A(T('edit'),_href=URL(r=request,c='default',f='data/update/
sarua', args=str(value)))),
        LI(A(T('remove'),_href=URL(r=request, c='default',f='data/
delete/sarua', args=str(value)))))

    ss = session.vars.searchfor
    if not ss :
        query = None
    elif session.vars.operator == 'equals':
        query = db.sarua[session.vars.field]==ss.upper()
    elif session.vars.operator == 'starts with':
        query = db.sarua[session.vars.field]>=ss.upper()
    else:
        query = db.sarua[session.vars.field].like('%'+ss+'%')
    session.flash = query
    rows = db(query).select(db.sarua.ALL,limitby = (0,25))
    records = SQLTABLE(rows,
headers=dict([('sarua.'+f,db.sarua[f].label)
                                     for f in db.sarua.fields]))
    return dict(records=records)


On Feb 8, 2:56 pm, Johann Spies <[email protected]> wrote:
> I want to use a form to build a query for a search function and do not
> understand the communication between the different functions.  I have:
>
> def index():
>     form = FORM(TABLE(TR('Field:','',
>                          SELECT(
>                              OPTION('title', _field = 1),
>                              OPTION('affiliation', field = 2),
>                              OPTION('country', field = 3),
>                              OPTION('year', field = 4),
>                              OPTION('research_field', field = 5),
>                              OPTION('journal', field = 6),
>                              OPTION('keywords', field = 7),
>                              OPTION('author',field = 8),
>                              OPTION('source', field= 8), field = 1)),
>                       TR('Operator:', '',
>                          SELECT(
>                              OPTION('equals', operator = 1),
>                              OPTION('starts with', operator = 2),
>                              OPTION('contains', operator = 3), operator =1)),
>                        TR('Value:', '',
>                          INPUT(_searchfor = '')),
>                       TR('', '', INPUT(_type = 'submit' ))))
>     if form.accepts(request.vars, session):
>         redirect(URL(r=request, f='list_records'))
>     elif form.errors:
>         response.flash = 'form has errors'
>     else:
>         response.flash = 'Please select the field, operator and type
> in the search field'
>     return dict(form=form)
>
> And
> def list_records():
>     db.sarua.id.represent = lambda value: UL(
>         LI(A(T('edit'),_href=URL(r=request,
> c='default',f='data/update/sarua', args=str(value)))),
>         LI(A(T('remove'),_href=URL(r=request,
> c='default',f='data/delete/sarua', args=str(value)))))
>
>     try:
>         ss = session.vars.searchfor.upper()
>     except:
>         ss = session.vars.searchfor
>     if not ss :
>         query = ''
>     elif session.vars.operator == 'equals':
>         query = "db.sarua.%s == %s" % (session.vars.field, ss)
>     elif session.vars.operator == 'starts with':
>         query = "db.sarua.%s >= %s" % (session.vars.field, ss)
>     else:
>         query = "db.sarua.%s.like( '%' + %s + '%')" % (session.vars.field, ss)
>     session.flash = query
>     rows = db(query).select(db.sarua.ALL,limitby = (0,25))
>     records = SQLTABLE(rows, headers=dict([('sarua.'+f,db.sarua[f].label)
>                                      for f in db.sarua.fields]))
>     return dict(records=records)
>
> But the variables do not arrive in list_records().  I am missing
> something about request vars, return(form) and session vars().
>
> If I replace "session" in list_records with "response" I do not get
> any error but also no query content.
>
> How am I supposed to do it?
>
> Regards
> Johann

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
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.

Reply via email to