hello one and all,

i am trying to create a form to takes people's opinion within each section 
contained by a DIV.  so my html page might have one or ten sections, each 
one containing a loop created form.  so here is some pseudo code:

first the table structure:
db.define_table('lecture_item_opinions',
    Field('lecture_id', db.lectures, requires=IS_IN_DB(db, db.lectures.id, 
'%(title)s (%(id)s)'), writable=False, readable=False),
    Field('lecture_item_id', db.lecture_items, requires=IS_IN_DB(db, 
db.lecture_items.id, '%(title)s (%(id)s)'), writable=False, readable=False),
    Field('survey_datetime', 'datetime', comment="format YYYY-MM-DD 
HH:MM:SS.milliseconds", requires=IS_NOT_EMPTY(), 
default=datetime.datetime.today(), writable=False, readable=False),
    Field('user_id', db.auth_user, requires=IS_IN_DB(db, '%s.id' % 
db.auth_user, '%(last_name)s, %(first_name)s (%(id)s)'), writable=False, 
readable=False),
    Field('opinion', 'text', requires=IS_NOT_EMPTY(), comment='Please give 
your honest opinion and constructive criticism of this segment. This will 
help the instructor improve the content and presentation of his/her 
lectures and it is readable and private to the instructor\'s eyes only.'),
    format = '%(id)s')
    
and here is the pseudo code:

    qry = (t.lecture_id==lecture.id)
    items = db(qry).select(orderby=t.order_by | t.title)
    for i in items:
        d = DIV()
        d.append(H3(i.title))
        d.append(P(XML(i.text_before)))
        if auth.is_logged_in():
            x = DIV(_class="body_news")
            o = db.lecture_item_opinions
            if (i.user_id==auth.user_id):
                opinions = 
db(o.lecture_item_id==i.id).select(orderby=o.survey_datetime)
                for o in opinions:
                    x.append(P(o.opinion))
                d.append(x)
            elif (len(usr.create_lecture_foldername)==0):
                f = SQLFORM(o, formstyle='table2cols')
                f.vars.lecture_id=lecture.id
                f.vars.lecture_item_id=i.id
                f.vars.user_id=auth.user_id
                x.append(CAT(H4('Please give your Opinion of this 
Section'), f))
                d.append(x)
        body.append(d)

and i have noticed with say two DIV opinion forms that web2py is giving 
different values for the _formkey.  good.  so why is it when a user enters 
in their opinion and pushes submit, it does not enter the opinion in the 
database?  is there a better way to structure this so that the function 
accepts the processed form?  what is the best method of creating forms via 
a loop or on the fly based on database records?

thanx in advance, lucas

Reply via email to