If you are using crud, you should not do form.accepts -- crud.create will 
handle the form.accepts for you. 
See http://web2py.com/book/default/chapter/07#CRUD.

Anthony

On Wednesday, September 7, 2011 4:29:24 PM UTC-4, Omi Chiba wrote:
>
> I'm creating a simple twitter like app for fun. To submit worked with 
> {{=form}} and now I'm using form.custom.xxx for customization. 
>
> It works fine if I comment out the following from default.py but 
> form.vars will be empty and the record will not be created with the 
> two lines. 
>
> if form.accepts(request.vars, session): 
>         redirect(URL()) 
>
> Any idea what's happening and do you know how to solve this problem? 
>
>
> db.py 
> ---------- 
> db.define_table('comment', 
>     Field('body', 'text', length=140), 
>     Field('created_on', 'datetime', default=request.now), 
>     Field('created_by', db.auth_user, default=auth.user_id, 
> ondelete='NO ACTION')) 
>
> db.comment.body.requires = IS_NOT_EMPTY() 
> db.comment.created_on.writable = db.comment.created_on.readable = 
> False 
> db.comment.created_by.writable = db.comment.created_by.readable = 
> False 
>
> default.py 
> --------------------- 
> @auth.requires_login() 
> def index(): 
>     comments = db().select(db.comment.ALL, 
> orderby=~db.comment.created_on) 
>     form = crud.create(db.comment) 
>     if form.accepts(request.vars, session): 
>         redirect(URL()) 
>     return dict(comments=comments, form=form) 
>
> default/index.html 
> ---------------------------------- 
>
> {{extend 'layout.html'}} 
>
> <h1>What's happening ?</h1> 
> {{=form.custom.begin}} 
> {{=form.custom.widget.body}} 
> {{=form.custom.submit}} 
> {{=form.custom.end}} 
>
> {{=BEAUTIFY(request.vars)}} 
> {{=form.vars}} 
>
> <h1>What's happened ?</h1> 
> {{for comment in comments:}} 
> <div><b>{{=db.auth_user[comment.created_by].first_name}} 
> {{=db.auth_user[comment.created_by].last_name}}</b> - {{=comment.body}} 
> </div> 
> <br/> 
> {{pass}} 
>

Reply via email to