It's an extra hassle to have multiple fields with the same name in a given form because you get back a list for each common name. Instead, you're better off just creating a custom form via SQLFORM.factory, naming each field uniquely. Then do the inserts with the form.vars values after validation.
Anthony On Sunday, May 22, 2016 at 2:01:27 PM UTC-4, Mohit Jain wrote: > > Hello, > I have 2 tables (ApplicationDeadline & NominationDeadline). Both of > them have only 2 fields (start-time and end-time). I would like to create a > form where the user can see 4 fields and only one submit button that can be > used to insert new values of these fields. Only the fields that have been > filled by the user must be inserted (blank fields must not have new > insertions). This is somewhat similar to what is given in the manual ( > http://web2py.com/books/default/chapter/29/07/forms-and-validators#One-form-for-multiple-tables) > > however, I don't have a common foreign-key (like the client-id of the given > example) and hence would like to know how to do such a thing, if at all > possible. > > models/db.py > ####################################### > # Set the Application Period Deadline.# > ####################################### > db.define_table( > 'AppDeadline', > Field('start','datetime',required=True, label='Start Time'), > Field('end','datetime',required=True, label='End Time') > ) > > > ####################################### > # Set the Nomination Period Deadline.# > ####################################### > db.define_table( > 'NomDeadline', > Field('start','datetime',required=True, label='Start Time'), > Field('end','datetime',required=True, label='End Time') > ) > > What I want is *something like,* > > form = SQLFORM.factory(db.AppDeadline, db.NomDeadline) > if form.process().accepted: > if form.vars.appTime: #To check if application-fields have been > updated > response.flash = 'Application Period Set : '+str(form.vars.start)+' > to '+str(form.vars.end) > db.UserLogs.insert(activity='Application Period Set : '+str(form. > vars.start)+' to '+str(form.vars.end)) > if form.vars.nomTime: #To check if nomination-fields have been updated > response.flash = 'Nomination Period Set : '+str(form.vars.start)+' > to '+str(form.vars.end) > db.UserLogs.insert(activity='Nomination Period Set : '+str(form. > vars.start)+' to '+str(form.vars.end)) > elif form.errors: > response.flash = 'Form has error(s)!' > > > Regards, > Mohit > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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/d/optout.