Formating forms manually

19 views
Skip to first unread message

BG

unread,
Sep 24, 2009, 7:41:11 PM9/24/09
to web2py-users
Hello,

I am new to web2py and am in process of implementing a form. I would
like to be able to format the form layout manually in the view. Is
there a way to do this? How can I individually render form elements
in the view?

Using FORM() helper to create the form.

Thanking you in advance

Bill

waTR

unread,
Sep 24, 2009, 7:51:53 PM9/24/09
to web2py-users

BG

unread,
Sep 24, 2009, 9:56:23 PM9/24/09
to web2py-users
Hi waTR,

Thank you for your help.

Although, like Arvind in the conversation you send me, I have objects
that span multiple tables. Is there any other way of getting at the
form elements with FORM() or utilizing SQLFORM across multiple models?

Bill

weheh

unread,
Sep 25, 2009, 12:26:51 AM9/25/09
to web2py-users
You need to use SQLFORM.factory and then you can use custom forms in
view by bracketing the form content with
{{=form1.custom.begin}}
custom form content
{{=form1.custom.end}}.

Be sure to have a hidden input with the form name and that the form
name is referenced in the controller's accept method
if form1.accepts(request.vars,formname="form1"):
response.flash='form accepted'
You can reference multiple tables in SQLFORM.factory
(db.table1,db.table2,...) but the fields in the tables must have
unique names, i.e. this won't work if db.table1 has field "name" and
db.table2 has field "name".

You may have to turn off fields that aren't being used but that have
requires validators. Do this in the controller by
db.table1.field1.readable=db.table1.field1.writable=False


You also will have to manually insert into the db in the accepts
clause with a statement like this:
db.table1.insert(field1=form1.vars.field1)

Hope this helps.

waTR

unread,
Sep 25, 2009, 2:00:21 PM9/25/09
to web2py-users

BG

unread,
Sep 26, 2009, 5:57:47 PM9/26/09
to web2py-users
weheh,

Thank you so much!

Very helpful! Let me give it a try!

Bill

BG

unread,
Sep 26, 2009, 5:59:51 PM9/26/09
to web2py-users
Hi waTR,

Thank you very much for your continued help!

Bill
Reply all
Reply to author
Forward
0 new messages