Thanks Anthony... Here what I did so far...
## CONTROLLER def bunch_review_with_multi_form(): # Getting lot and test from args or vars... rows = db((db.lotns_lot_number.id == request.args(1))&\ (db.lotns_sample.lot_number_id == db.lotns_lot_number.id)&\ (db[request.args(0)].sample_id == db.lotns_sample.sample_id)).select\ (db.lotns_lot_number.lot_number_computed, db.lotns_sample.sample_code, \ db[request.args(0)].ALL, orderby=db.lotns_sample.sample_code) forms = [] flag = 0 for i in rows: forms.append(SQLFORM(db[request.args(0)], i[request.args(0)].id)) forms[flag].process(detect_record_change=True) if forms[flag].record_changed: response.flash = T('form have changed between the time you edited and submitted it, please have a look on the data again') elif forms[flag].accepted: session.flash = T('form accepted').capitalize() #redirect(URL(request.application,c=request.controller,f='read',args=(request.args[0],request.args[1]))) else: response.flash = T('please correct the form') flag+=1 return dict(forms=forms) ###VIEW {{extend 'layout_form.html'}} {{for i in range(0,len(forms)):}} {{=forms[i]}} {{pass}} I am confuse and I am not sure if my controller can works independently with each form embeded into forms the way I wrote my controller function... What's the way you were telling me to do?? Thanks PS.: Is there any way I can make a multiple lines update with SQLFORM or .grid or .smartgrid?? Richard On Mon, Dec 12, 2011 at 2:40 PM, Anthony <abasta...@gmail.com> wrote: > web2py creates a hidden _formname field for each form. If there are > multiple forms on the page, they must each have a unique _formname. By > default, SQLFORM creates a _formname based on the table name and type of > form (and possibly record number), but you can generate your own name via > the 'formname' argument to form.accepts (or form.validate, or > form.process). If you want to create update forms, though, you don't have > to manually fill in the field values -- just pass the record as the second > argument to SQLFORM. Also, in that case, you'll automatically get a unique > _formname for each form because the record id becomes part of the > _formname. See > http://web2py.com/book/default/chapter/07#SQLFORM-and-insert/update/delete > . > > Also, rather than having a new variable for each form (i.e., form0, form1, > etc.), which makes the code rather messy, why not just make a list of forms? > > forms = [] > forms.append(SQLFORM(...)) # add a new form to the list > form[i] # to reference the i-th form > > You might also consider creating each form as an Ajax component, or at > least submitting the forms via Ajax, so the whole page of forms doesn't > have to get re-processed when just a single form is submitted. > > Anthony > > On Monday, December 12, 2011 1:43:05 PM UTC-5, Richard wrote: >> >> Hello, >> >> Is there a better way of doing this : >> >> def bunch_update_with_multi_form()**: >> form0=None >> form1=None >> form3=None >> form4=None >> form5=None >> form6=None >> form7=None >> form8=None >> form9=None >> form10=None >> form11=None >> form12=None >> form13=None >> form14=None >> form15=None >> form16=None >> form17=None >> form18=None >> form19=None >> form20=None >> form21=None >> form22=None >> form23=None >> form24=None >> form25=None >> form26=None >> form27=None >> form28=None >> form29=None >> form30=None >> >> form_num = 0 >> for i in rows: >> globals()['form%s'%form_num] = SQLFORM(db[request.args(0)]) >> for f in db[request.args(0)].fields: >> if globals()['form%s'%form_num] != None: >> globals()['form%s'%form_num].**vars[f] = >> i[request.args(0)][f] >> if globals()['form%s'%form_num] != None: >> if globals()['form%s'%form_num].**process().accepted: >> response.flash = '...' >> elif globals()['form%s'%form_num].**errors: >> response.flash = 'form has errors' >> form_num+=1 >> return >> dict(table=table,form0=form0,**form1=form1,form2=form2,form3=** >> form3,form4=form4,form5=form5,**form6=form6,form7=form7,form8=** >> form8,form9=form9,form10=**form10,form11=form11,form12=** >> form12,form13=form13,form14=**form14) >> >> When using web2py shell I don't have any problem to execute my loops, >> but in app I am getting only one correct form on 14... >> >> I read in the book that SQLFORM is creating it on unique form >> identifier but there is no example about that... Should I user SQLFORM >> in view (put my loop there) to make it works : >> >> Thanks >> >> Richard >> >>