简体   繁体   中英

Web2py Form fails to process at first try

I created a SQLFORM that creates a new entry and also a FORM to delete that entry. But when I try to use that FORM (fill it and hit the submit) but at the first try it always returns false.

form.process().accepted:

My controllers :

def new_category():
    form = SQLFORM(db.category)
    if form.process().accepted:
        response.flash = 'category create form accepted'
    return dict(form=form)

def delete_category():
    form = FORM(INPUT(_name='name', requires=IS_NOT_EMPTY()),\
                INPUT(_type='submit'))
    if db(db.category.name==request.vars.name).select():
        if form.process().accepted:
            response.flash = 'category delete form accepted'
            db(db.category.name==request.vars.name).delete()
        else:
            response.flash = 'category delete form refused'
    else:
        response.flash = 'category delete form refused (no category)'
    return dict(form=form)

My Models :

db.define_table('category',Field('name'))

My create / delete views :

{{extend 'layout.html'}}
<h2>This is the test/delete_category.html template</h2>
{{=form}}

{{extend 'layout.html'}}
<h2>This is the test/new_category.html template</h2>
{{=form}}

After the first try (when i fill the form and submit it) it works as it should. I look at similiar question at in here but using accepts(request) doesn't work either.

Thank you for your help .

your model looks peculiar, for you haven't set what is the data type of Field name. it should be ....Field('name','string')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM