【发布时间】:2018-11-19 10:39:26
【问题描述】:
我在我网站的页脚(footer.pug)中提交了一个简单的联系表格:
form(method="POST" action="contact_form")
input(type='email' name='ct_email' data-name='ct_email' required)
textarea(type='text' name='ct_message' data-name='ct_message' required)
button(type='submit') Send
由于表单在模板中,并且整个站点都使用页脚模板,因此可以从各种途径提交表单:
/contact_form/route1/contact_form/route1/de/contact_form- 等等……
所以现在看来我必须为所有可能的路线创建一个处理程序:
router.post('/contact_form', function(req, res, next) {
// ...
}
router.post('/route1/contact_form', function(req, res, next) {
// ...
}
如何轻松处理来自所有路由的 POST 请求无需为每个路由编写处理程序?
【问题讨论】:
标签: node.js forms express routing