[web2py] custom form validation doesn't work

2012-12-15 Thread jonas
Hi. 

I have a default form that is passed in view: {{=form}}
using this validation and insertion works. but when I use a custom form 
none of that works. why?
Also form.process().accepted works only when using default form. 

My second question is: when submitting the form I redirect to index, and 
all entries in the db are returned. Is that because i reuse the index 
function? Is there any way to clear all fields after a successful submit?

the code: 

default.py:

def index():

query=db.blog.id>0
res=db(query).select(orderby=~db.blog.date)
query=db.about.id>0
about=db(query).select()
query=db.comments.post_id>0
com=db(query).select(orderby=~db.comments.created_on)

return dict(res=res,about=about,com=com,message=T('Everything should be 
made as simple as possible, but not simpler'))

def comment():

""" create comment form. Every comment is id locked to the specific 
post """

post=db(db.blog.id==request.args(0)).select().first()
db.comments.post_id.default=post.id
form=crud.create(db.comments)
if form.process().accepted:
print 'form accepted'
redirect(URL('index'))
else:
print 'not accepted'
return dict(form=form)

index.html:

{{=A(TAG.i(_class="icon-plus-sign"), _rel="tooltip", _title="testing", 
_class="btn", _href='#', _onclick="jQuery('#uc').toggle();")}}

  {{=LOAD('default','comment.load',args=result.id,ajax=True)}}


comment.load:

{{=form}}

thanks

-- 





[web2py] custom form validation

2012-12-14 Thread jonas
Hi

I have a custom comment form:

def comment():

""" create comment form. Every comment is id locked to the specific 
post """

#crud.settings.create_next = URL('index')
post=db(db.blog.id==request.args(0)).select().first()
db.comments.post_id.default=post.id
form=crud.create(db.comments)
if form.process().accepted:
print 'form accepted'
else:
print 'not accepted'
return dict(form=form)
#return LOAD('default','comment.load',args=post.id,ajax=True)

comment.load:

{{=form.custom.begin}}

  date: {{=form.custom.widget.created_on}}


  name: {{=form.custom.widget.created_by}}


  mail: {{=form.custom.widget.mail}}


  link: {{=form.custom.widget.link}}


  comment:{{=form.custom.widget.comment}}

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

that is called from index.html:

{{=A(TAG.i(_class="icon-plus-sign"), _rel="tooltip", _title="testing", 
_class="btn", _href='#', _onclick="jQuery('#uc').toggle();")}}

  {{=LOAD('default','comment.load',args=result.id,ajax=True)}}


but the form.process().accepted doesn't work even though everything if 
filed correctly. why? 

--