FORM object

16 views
Skip to first unread message

Arvind

unread,
Sep 22, 2009, 5:30:16 PM9/22/09
to web2py-users
Hello,

I have been going through the book, but i dont see a list of complete
form objects.

Where can i find a list of all the objects.
With hit and trial, i managed to get form.formname.
But how can I get a complete list of the form objects/attributes ?



thanks
Arvind

Thadeus Burgess

unread,
Sep 22, 2009, 6:02:33 PM9/22/09
to web...@googlegroups.com
print dir(form) - to get variables/methods
print dir(form.attributes) - dict of attributes (formname, id, etc.)

Gotta love the dir command.

-Thadeus

waTR

unread,
Sep 22, 2009, 8:33:29 PM9/22/09
to web2py-users
Easier, and far more useful way is to use epydocs.
http://www.web2py.com/examples/static/epydoc/index.html

I have epydoc open all the time while I am working with web2py. It is
an incredibly useful resource. Though, it would be FAR more useful, if
web2py had better code commenting. My rule for good commenting is 2
lines of comments to 1 line of code (this doesn't mean every line gets
commented...that would be stupid). The way I apply this rule is by
using good doc strings and descriptions of goals at beginning of
functions/methods.




On Sep 22, 3:02 pm, Thadeus Burgess <thadeus.burg...@gmail.com> wrote:
> print dir(form) - to get variables/methods
> print dir(form.attributes) - dict of attributes (formname, id, etc.)
>
> Gotta love the dir command.
>
> -Thadeus
>

Arvind

unread,
Sep 22, 2009, 11:53:54 PM9/22/09
to web2py-users
> Easier, and far more useful way is to use epydocs.http://www.web2py.com/examples/static/epydoc/index.html

Thanks a ton. this is superb... just too good to be true. :-)

Arvind

unread,
Sep 23, 2009, 12:46:03 AM9/23/09
to web2py-users
Hello,

> print dir(form) - to get variables/methods
> print dir(form.attributes) - dict of attributes (formname, id, etc.)
>

I might sound really silly. Where do i place the print command ? it
wont work in the controller or in the view.

and I am still not clear....
if I have a form, like this
form = FORM("your name:",
INPUT(_name="yourname",requires=IS_NOT_EMPTY()),
INPUT(_type="submit"))



How can i place the elemets of the form in a customized way....
something like this
<table>
<tr> <td> {{=form.label}} </td> </tr>
<tr> <td> {{=form.input._name}} </td> </tr>
<tr><td><td></tr>
<tr><td><td></tr>
<tr><td><td></tr>

<tr> <td> {{=form.submit}}</td> </tr>

Note... in the above example, I have chosen to place the submit button
after 3 rows... this way, i get to place my form, in my own way,
rather than web2py automatically placing them in a table or in its own
way.


thanks
Arvind

Fran

unread,
Sep 23, 2009, 2:43:07 AM9/23/09
to web2py-users
On Sep 23, 5:46 am, Arvind <arvind.ran...@gmail.com> wrote:
> > print dir(form) - to get variables/methods
> > print dir(form.attributes) - dict of attributes (formname, id, etc.)
> I might sound really silly. Where do i place the print command ? it
> wont work in the controller or in the view.

Web2Py shell.
Either at OS CLI or via the appadmin CLI.

I do loads of little experiments/explorations in the shell to try
stuff out quickly before transferring to the text files that make up
the app.

> and I am still not clear....
> if I have a form, like this
>     form = FORM("your name:",
>                  INPUT(_name="yourname",requires=IS_NOT_EMPTY()),
>                  INPUT(_type="submit"))

I don't find it terribly useful to use FORM - using SQLFORM or crud is
generally more useful.

> How can i place the elemets of the form in a customized way....
> something like this
> <table>
>      <tr> <td> {{=form.label}} </td> </tr>

Not sure about FORM, but SQLFORM is:
{{=form.custom.begin}}
{{=form.custom.label.myfield}}

>      <tr> <td> {{=form.input._name}} </td> </tr>

Likewise
{{=form.custom.widget.myfield}}

>      <tr> <td> {{=form.submit}}</td> </tr>

{{=form.custom.submit}}
{{=form.custom.end}}

> Note... in the above example, I have chosen to place the submit button
> after 3 rows... this way, i get to place my form, in my own way,
> rather than web2py automatically placing them in a table or in its own
> way.

This is the whole point of custom forms, yes - you get all the
benefits of the self-processing forms, whilst retaining the ability to
keep full control of the layout.

F

waTR

unread,
Sep 23, 2009, 11:21:14 AM9/23/09
to web2py-users
I also like to keep the cheet sheet open while I work. IT is a great
QUICK reference, when the searching the Manual takes too long for
simply the names of things.
http://www.web2py.com/examples/static/web2py_cheatsheet.pdf

For custome HTML forms check the Manual page 194 (SQLFORM in HTML).
http://www.scribd.com/doc/19211452/Web2py-Manual

Enjoy!

Arvind

unread,
Sep 23, 2009, 1:51:29 PM9/23/09
to web2py-users

> I don't find it terribly useful to use FORM - using SQLFORM or crud is
> generally more useful.

I find, that for SQLFORM i have to specify some database ...which I do
not want to .

My single object spans across multiple tables...

So to create my single object, i need over 10 fields in a form, Maybe,
it seems, that MVC is not the pattern for me here.

Also why not SQLFORM.factory ?

Lots of things out there, but, my understanding is not very clear.

any advice ?

thanks
Arvind

p.s. how do you open a web2py shell ?

Thadeus Burgess

unread,
Sep 23, 2009, 2:00:33 PM9/23/09
to web...@googlegroups.com
SQLFORM.factory is just like SQLFORM however it does not connect to a database(meaning you don't have to have any physical models)

you use SQLFORM.factory just like db.define_table()

form = SQLFORM.factory(Field('user', requires=IS_IN_DB()), Field('someotherfieldfromalargerelationship', 'boolean'))

then form.accepts(request.vars, session)

db[userid] = request.vars.id
db[someother] where userid==userid = request.vars.someotherfieldblahblah


-Thadeus
Reply all
Reply to author
Forward
0 new messages