Good catch Anthony... @Steve it exactly what I have in mind, except in my case the form has to be generic for many differents tables, but if you only one table to bunch insert, that way it works fine...
Notice, if you create more inputs then the number your users will need (not 3 records for instance) you get in trouble if you have not null requires or IS_IN_DB or other validators)... So I use an other form to catch the number of input the user is needing and I pass it buy the URL as a vars something like that : URL(c='controller', f='bunch_func', vars=dict(nb_inputs=3)) Then I use it in range function : for i in range(0, int(request.vars.nb_inputs)) ... Also, you have to use custom form in the view to put the fields in a table and display the field labels only in the th of the table header something like that : {{=form.custom.begin}} <div style="overflow-y:auto;" width="90%";> <table class="batch_insert sortable" > <tr class="batch_insert"> {{for i, field_name in enumerate(fields_subset_batch_insert):}} {{if field_name == 'field1':}} <th class="th0 batch_insert">{{=db[request.args(0)][field_name].label}}</th> {{else:}} <th class="batch_insert">{{=db[request.args(0)][field_name].label}}</th> {{pass}} {{pass}} </tr> {{for i in range(0,int(request.vars.nb_inputs)):}} <tr> {{for field_name in fields_subset_batch_insert:}} {{if field_name == 'field1':}} <td class="td0 batch_insert">{{=form.custom.widget['%s_%s' %(field_name, i)]}}</td> {{else:}} <td class="batch_insert">{{=form.custom.widget['%s_%s' %(field_name, i)]}}</td> {{pass}} {{pass}} </tr> {{pass}} </table> </div> <br/> {{=form.custom.submit}} {{=form.custom.end}} I was waiting to get a more detailed explanation with the CSS, etc. But it take time for that :) Richard On Sat, Mar 16, 2013 at 2:03 PM, Anthony <abasta...@gmail.com> wrote: > There is no form.vars.company -- it's form.vars.company_0, > form.vars.company_1, etc. So: > > db.company.insert(company=form.vars['company_%s' % i]) > > Anthony > > > On Saturday, March 16, 2013 9:27:11 AM UTC-4, 黄祥 wrote: >> >> yeah my mistake i didn't notice, thanks for correcting me, anthony. i've >> already test the form is work fine, but it can't insert it into database. >> i've tried to add some code for that but the result is not expected (no >> error occured), here is the database table content, after i input and >> submit it. the others strange is when i refresh the page, the table is fill >> it up with the data (not input by me). >> >> company.id<http://127.0.0.1:8000/test/appadmin/select/db?orderby=company.id> >> company.company<http://127.0.0.1:8000/test/appadmin/select/db?orderby=company.company> >> 1 >> <http://127.0.0.1:8000/test/appadmin/update/db/company/1>None_02<http://127.0.0.1:8000/test/appadmin/update/db/company/2> >> None_13 >> <http://127.0.0.1:8000/test/appadmin/update/db/company/3>None_24<http://127.0.0.1:8000/test/appadmin/update/db/company/4> >> None_05 >> <http://127.0.0.1:8000/test/appadmin/update/db/company/5>None_16<http://127.0.0.1:8000/test/appadmin/update/db/company/6> >> None_27 >> <http://127.0.0.1:8000/test/appadmin/update/db/company/7>None_08<http://127.0.0.1:8000/test/appadmin/update/db/company/8> >> None_19 <http://127.0.0.1:8000/test/appadmin/update/db/company/9>None_2 >> >> >> db.py >> db.define_table('company', >> Field('company')) >> >> default.py >> def index(): >> inputs = [] >> for i in range(0,3): >> inputs.append(db.company.**company.clone(name='%s_%s' % ( >> db.company.company.name, i))) >> form = SQLFORM.factory(*inputs) >> if form.process().accepted: >> for i in range(0,3): >> db.company.insert(company='%s_**%s' % (form.vars.company, i)) >> elif form.errors: >> response.flash = 'form has errors' >> return dict(form=form) >> >> index.html >> {{extend 'layout.html'}} >> {{=form}} >> >> is there something wrong in my code above? >> thank you >> > -- > > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.