简体   繁体   中英

web2py custom form doesn't submit

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

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.

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