web2py custom form doesn't submit

2019-09-18 10:31发布

问题:

I cant seem to submit my form with this code:

@auth.requires_login()
def index():
    db.post.answers.writable=False
    db.post.answers.readable=False
    form = SQLFORM(Post, formstyle='divs')
    if form.process().accepted:
        pass
    code.....
    return(form=form)

view:

{{=form.custom.begin}}
<div class="chat-form">
    <textarea></textarea>
    <button>Send</button>
</div>
{{=form.custom.end}}

My db is empty with no data submitted.Please help Regards

回答1:

You must specify "name" attributes for your HTML input elements, and if you are using SQLFORM with a web2py DAL model, the input names must match the names of the model fields. So, in the example you have shown, you would need:

<textarea name="answers"></textarea>

Without the "name" attribute, the browser will not send the data. And if the name does not match any fields in the DAL model, web2py will not do anything with the submitted data.



标签: forms web2py