Two forms, one page

501 views
Skip to first unread message

Larry Wapnitsky

unread,
Mar 20, 2012, 4:49:15 PM3/20/12
to web...@googlegroups.com
I know it's possible to have multiple forms on one page, but is it possible to have one submit button that submits data based on both forms?

I have a SQLFORM field that takes multiple entries.

This is followed by a CRUD form based on the DAL (MySQL).

I'd like to parse the data in the SQLFORM (multiple, individual entries) and add them one by one as unique values to the DAL with the information in the CRUD portion (data common to all entries).

Is this possible?

Thanks.

pbreit

unread,
Mar 20, 2012, 5:19:31 PM3/20/12
to web...@googlegroups.com
I think you're going to run into problems in Web2py since even if you use Custom Forms (http://web2py.com/books/default/chapter/29/7#Custom-forms) you're going to have two conflicting security keys (hidden fields to prevent CSRF attacks).

If you're able to paint the form correctly in the view, then you're going to need to write most or all of the processing and db updating logic in your controller.

There might be a Jquery based approach which works better. Perhaps you could have a Javascript function post back the two forms individually to controllers designed to handle each. Sorry not more helpful.

Niphlod

unread,
Mar 20, 2012, 5:38:30 PM3/20/12
to web...@googlegroups.com
why not using SQLFORM.factory for having one form for all the data ?

in the controller logic, then, something like

for f in form.vars.multiple_field:
          db.mysqltable.validate_and_insert(foo=form.vars.foo, bar=form.vars.bar, uniquefield=f)

should do the job.

With no example model supplied, this is all the help you can get ^_^

weheh

unread,
Mar 21, 2012, 12:16:43 AM3/21/12
to web2py-users
I think you're going to have some trouble with this. Your best bet is
to go with SQLFORM.factory. problem is, you lose your nice CRUD
functionality. But it gives you complete control.

Another approach, the one that I use, is to hide the various forms
behind accordion folds. That way, you only have one submit button at a
time in the view.

Larry G. Wapnitsky

unread,
Mar 21, 2012, 7:54:55 AM3/21/12
to web...@googlegroups.com
Thanks, Niphlod & pbreit. Still learning, and asking questions is how I
do it. I'll work on your suggestions f

FYI, Niphlod - this is the same app as in the other thread.

Cliff

unread,
Mar 21, 2012, 10:10:20 AM3/21/12
to web2py-users
> Another approach, the one that I use, is to hide the various forms
> behind accordion folds.

Or on different tabs.

In either case, update the fields on the tab or fold being closed to
avoid losing input.

You can use ajax for this.
Reply all
Reply to author
Forward
0 new messages