我试图做一个定价表单,每个表单都有一个隐藏值,我的目标是在用户点击提交按钮后将值发送到'/billing'
路由,起初我认为它是一个客户端问题,我找到了这个解决方案
Processing multiple forms in one page using Mongodb and node.js
但它不是客户端问题。
例如
定价-table.ejs
<form method="GET" action="/billing">
<input type="hidden" name="plan" value="monthly" />
<button>Submit</button>
</form>
<form method="GET" action="/billing">
<input type="hidden" name="plan" value="yearly" />
<button>Submit</button>
</form>
app.js
app.get('/pricing', function(req, res) {
var plan = req.body.plan;
console.log(plan); // It will printout undefined, probably because It doesn't know which form belong to which one.
res.render('pricing-table', { plan: plan });
});
app.get('/billing', function(req, res) {
// Do some mongoose stuff
});