It's not the variable referring to the form that needs to be unique (you 
can simply append the forms together using CAT() or inside a DIV) -- 
rather, each form has a name stored in a hidden _formname field. It is set 
by specifying the "formname" argument to .accepts() or .processs().

f = SQLFORM(db.opinions)
[more code]
f.process(formname='myform_%s' % i.id)

When you create the forms, you can do so in a loop and append them all 
together. However, when a specific form is submitted, you don't want to 
create and process all the forms again because you only need to create and 
process the submitted form. So, check for request.vars._formname, and if 
present, just create and process that one form (use the value in 
request.vars._formname to set the "formname" argument in the call to 
.process()).

Anthony

On Monday, May 14, 2012 10:05:09 PM UTC-4, lucas wrote:
>
> i did try messing around with
>
>                 f = SQLFORM(db.opinions)
>                 f.vars.stuff.assignments...
>                 exec 'f%s = %s' % (i.id, f)
>                 if (exec 'f%s' % i.id).process().accepted:
>                     session.flash = 'Thank you for your opinion'
>                 elif (exec 'f%s' % i.id).errors:
>                     response.flash = 'errors'
>
> where the first exec "compiled" upon save, but bugged with
>
> File "/opt/web-apps/web2py/applications/ilecture/controllers/default.py" 
> <https://192.168.0.2/admin/default/edit/ilecture/controllers/default.py>, 
> line 206, in lecture
>     exec 'f%s = %s' % (i.id, f)
>   File "<string>", line 1
>     f1 = <form action="" enctype="multipart/form-data" 
> method="post"><table><tr class="even" 
> id="lecture_item_opinions_opinion__row1"><td class="w2p_fl"><label 
> for="lecture_item_opinions_opinion" 
> id="lecture_item_opinions_opinion__label">Opinion: </label></td><td 
> class="w2p_fc">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&#x27;s eyes only.</td></tr><tr class="odd" 
> id="lecture_item_opinions_opinion__row2"><td class="w2p_fw" 
> colspan="2"><textarea class="text" cols="84" 
> id="lecture_item_opinions_opinion" name="opinion" 
> rows="2"></textarea></td></tr><tr class="even" id="submit_record__row1"><td 
> class="w2p_fl"></td><td class="w2p_fc"></td></tr><tr class="odd" 
> id="submit_record__row2"><td class="w2p_fw" colspan="2"><input type="submit" 
> value="Submit" /></td></tr></table></form>
>          ^
>
> and the second and third exec would not even save.  so suggestions on how to 
> get this done 
> simply and gracefully would be fully appreciated.
>
>
>

Reply via email to