Prepopulate form

48 views
Skip to first unread message

Pai

unread,
Jan 30, 2008, 5:56:49 PM1/30/08
to web2py Web Framework
I'll try not to do mutliple post next time

Is there a way to prepopulate form?

in controller...

form=SQLFORM(db.comment,fields=['name','email','text'])

form.vars.email = current_user.email

return dict(form=form)


in view

{{=form}}

email field doesn't pre-populate the value

Massimo Di Pierro

unread,
Jan 30, 2008, 6:32:08 PM1/30/08
to web...@googlegroups.com
before form=SQLFROM

db.comment.name='whatever'

Pai

unread,
Jan 31, 2008, 12:15:10 PM1/31/08
to web2py Web Framework
I get this error when I tried to do that..

Traceback (most recent call last):
File "gluon\restricted.pyc", line 60, in restricted
File "applications/blog2/controllers/default.py", line 66, in
<module>
File "applications/blog2/controllers/default.py", line 54, in
addEditComment
File "gluon\sqlhtml.pyc", line 60, in __init__
AttributeError: 'str' object has no attribute 'default'


53 db.comment.email='te...@email.com'
54 form=SQLFORM(db.comment,fields=['name','email','text'])


I tried adding default value in the email in the db.py but that didn't
help.

any idea?

Pai

Massimo Di Pierro

unread,
Jan 31, 2008, 12:19:09 PM1/31/08
to web...@googlegroups.com
My mistake. I apologize.

> 53 db.comment.email.default='te...@email.com'


> 54 form=SQLFORM(db.comment,fields=['name','email','text'])

Massimo

Pai

unread,
Jan 31, 2008, 12:32:32 PM1/31/08
to web2py Web Framework
new error...


Traceback (most recent call last):
File "gluon\restricted.pyc", line 60, in restricted
File "applications/blog2/controllers/default.py", line 63, in
<module>
File "applications/blog2/controllers/default.py", line 52, in
addEditComment
File "gluon\sqlhtml.pyc", line 61, in __init__
File "gluon\sql.pyc", line 618, in formatter
AttributeError: 'tuple' object has no attribute 'reverse'

51 db.comment.email.default='tes...@yahoo.com'
52 form=SQLFORM(db.comment,fields=['name','email','text'])

I tried with and without having the default value declear in the
db.py. Still not luck.

If comment out the line 51, everything works fine.

Pai




On Jan 31, 11:19 am, Massimo Di Pierro <mdip...@cs.depaul.edu>
wrote:

Massimo Di Pierro

unread,
Jan 31, 2008, 12:37:51 PM1/31/08
to web...@googlegroups.com
I think in your model you have

db.table.field.requires=(.....)

instead of

db.table.field.requires=[.....]

let me know if that is the case.

Pai

unread,
Jan 31, 2008, 12:44:10 PM1/31/08
to web2py Web Framework
Ok I see the problem now. I actually have

db.table.email.requires=IS_EMAIL(),

I remove the commas that it works!

Thank you!

Pai

On Jan 31, 11:37 am, Massimo Di Pierro <mdipie...@cs.depaul.edu>
wrote:
> I think in your model you have
>
> db.table.field.requires=(.....)
>
> instead of
>
> db.table.field.requires=[.....]
>
> let me know if that is the case.
>
> On Jan 31, 2008, at 11:32 AM, Pai wrote:
>
>
>
> > new error...
>
> > Traceback (most recent call last):
> > File "gluon\restricted.pyc", line 60, in restricted
> > File "applications/blog2/controllers/default.py", line 63, in
> > <module>
> > File "applications/blog2/controllers/default.py", line 52, in
> > addEditComment
> > File "gluon\sqlhtml.pyc", line 61, in __init__
> > File "gluon\sql.pyc", line 618, in formatter
> > AttributeError: 'tuple' object has no attribute 'reverse'
>
> > 51 db.comment.email.default='test...@yahoo.com'
> > 52 form=SQLFORM(db.comment,fields=['name','email','text'])
>
> > I tried with and without having the default value declear in the
> > db.py. Still not luck.
>
> > If comment out the line 51, everything works fine.
>
> > Pai
>
> > On Jan 31, 11:19 am, Massimo Di Pierro <mdipie...@cs.depaul.edu>
> > wrote:
> >> My mistake. I apologize.
>
> >>> 53 db.comment.email.default='t...@email.com'
> >>> 54 form=SQLFORM(db.comment,fields=['name','email','text'])
>
> >> Massimo
>
> >> On Jan 31, 2008, at 11:15 AM, Pai wrote:
>
> >>> I get this error when I tried to do that..
>
> >>> Traceback (most recent call last):
> >>> File "gluon\restricted.pyc", line 60, in restricted
> >>> File "applications/blog2/controllers/default.py", line 66, in
> >>> <module>
> >>> File "applications/blog2/controllers/default.py", line 54, in
> >>> addEditComment
> >>> File "gluon\sqlhtml.pyc", line 60, in __init__
> >>> AttributeError: 'str' object has no attribute 'default'
>
> >>> 53 db.comment.email='t...@email.com'
Reply all
Reply to author
Forward
0 new messages