【发布时间】:2017-08-01 10:23:01
【问题描述】:
我正在尝试编写一个页面,向用户显示一个未经验证的帐户列表,每个帐户都有自己的表单元素。每个表单元素都有自己的“提交”按钮,该按钮向/verify 发送POST 调用。我遇到的问题是表单中的<p> 数据在/verify 中不可见。如何让服务器访问此表单数据?
此函数提供我们构建验证帐户页面的数据:
router.get('/verifyAccounts', function(req, res){
userData.find({"Verified": false}, function(err, user){
//console.log(user);
res.render('listUnverified', {listOf: user});
});
});
这个函数是我们试图将数据传递给的/verify函数:
router.post('/verify', function(req, res) {
//console.log(req.body);
var email = req.body.orgEmail;
console.log(email);
userData.update({"Email": email}, {$set: {"Verified": true}}, function(err, user) {
res.redirect('/verifyAccounts');
});
//res.redirect('/');
});
验证帐户页面的构建代码是:
<!doctype html>
<h1>THIS IS A LIST OF UNVERIFIED ORGANIZATION ACCOUNTS</h1>
{{# each listOf }}
<form action = "/verify" method="post">
<p name="orgName">{{ Org }}</p>
<p name="orgEmail">{{ Email }}</p>
<p name="orgPassword">{{ Password }}</p>
<button type="submit">Verify</button>
</form>
<br>
{{/each}}
所以基本上我想要的是/verify 函数能够访问单击“提交”按钮的表单中的字段,例如orgName 段落元素中的文本。知道如何实现吗?
【问题讨论】:
标签: javascript html node.js express handlebars.js