Thanks Anthony for your suggestion! Works just fine :) For anyone looking at a similar problem, here's what I've done now.
form = SQLFORM.factory( Field('appStart','datetime',label='App-Period Start Time'), Field('appEnd','datetime',label='App-Period End Time'), Field('nomStart','datetime',label='Nom-Period Start Time'), Field('nomEnd','datetime',label='Nom-Period End Time') ) if form.process().accepted: app_msg_flash = 'Application Period Unchanged' nom_msg_flash = 'Nomination Period Unchanged' if form.vars.appStart: if not form.vars.appEnd: session.flash = 'Application Period End-Time not specified!' redirect(URL('overall_admin','set_deadline')) else: db.AppDeadline.insert(start=form.vars.appStart, end=form.vars.appEnd) db.UserLogs.insert(activity='Application Period Set : '+str(form.vars.appStart)+' to '+str(form.vars.appEnd)) app_msg_flash = 'Application Period Set : '+str(form.vars.appStart)+' to '+str(form.vars.appEnd) elif form.vars.appEnd: session.flash = 'Application Period Start-Time not specified!' redirect(URL('overall_admin','set_deadline')) if form.vars.nomStart: if not form.vars.nomEnd: session.flash = 'Nomination Period End-Time not specified!' redirect(URL('overall_admin','set_deadline')) else: db.NomDeadline.insert(start=form.vars.nomStart, end=form.vars.nomEnd) db.UserLogs.insert(activity='Nomination Period Set : '+str(form.vars.nomStart)+' to '+str(form.vars.nomEnd)) nom_msg_flash = 'Nomination Period Set : '+str(form.vars.nomStart)+' to '+str(form.vars.nomEnd) elif form.vars.nomEnd: session.flash = 'Nomination Period Start-Time not specified!' redirect(URL('overall_admin','set_deadline')) response.flash = DIV(app_msg_flash,BR(),nom_msg_flash) elif form.errors: response.flash = 'Deadlines not Set : Form has error(s)!' On Sunday, May 22, 2016 at 11:31:27 PM UTC+5:30, 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.