Iterate through form (SQLFORM)

20 views
Skip to first unread message

vihang

unread,
Jan 20, 2010, 5:19:41 AM1/20/10
to web2py-users
Hello,

Is there any way I can iterate through a form? I want to construct a
form, with two elements in a row instead of one, and use CSS instead
of table.
I know there is form.custom, but there I have to give the form element
names explicitly. I want a generic solution for all forms I construct.
Also in form.components, the form opening and closing is not part of
it, (I guess).

Thanks
Vihang

DenesL

unread,
Jan 20, 2010, 9:07:53 AM1/20/10
to web2py-users
Vihang,
something like this should get you started:

for e in form.components[0]:
print e[0][0] # labels
print e[1][0] # non-labels

Denes

mdipierro

unread,
Jan 20, 2010, 10:22:47 AM1/20/10
to web2py-users
any helpers, including a form, is a three:

form[0] is the table in the form
form[0][i] is the i-th row
form[0][i][1] is the 2nd column of the i-th row
form[0][i][1][0] is the INPUT inside that
form[0]['_class'] is the class attribute of the table
form[0][i][1][0]['_name'] is the name attribute of the INPUT
form.element(_name='email')['_class'] is the class attribute of the
element with attribute name=='email'

etc.

You can manipulate and change the form structure and form attributes
in this was any way you want.

Reply all
Reply to author
Forward
0 new messages