如何解决无法使用Node JS从表单数据获取
我正在尝试从模态内的表单中获取输入并更新postgres中的输入字段。 但是,当我尝试获取输入字段时,结果是未定义的。
router.post('/changePassword',(req,res) => {
const emailReq = req.session.email;
const oldpasswordReq = req.body.password;
const newpasswordReq = req.body.newpassword;
if (oldpasswordReq !== newpasswordReq) {
const salt = bcrypt.genSaltSync();
const hash = bcrypt.hashSync(req.body.newpassword,salt);
knex('users').where({ email: emailReq })
.update({ password: hash })
.then(() => {
res.redirect('/');
});
res.render('/',{ title: 'Password changed'});
} else { (alert('The passwords are same')); };
});
模态中的形式如下ejs文件中
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Change Password</h4>
</div>
<div class="modal-body"><br><br>
<form method="post" action="/users/changePassword">
<div class="form-group">
<label for="usr">Old Password:</label>
<input type="password" class="form-control" id="oldpassword" name="oldpassword">
</div>
<div class="form-group">
<label for="pwd">New Password:</label>
<input type="password" class="form-control" id="newpassword" name="newpassword">
</div>
<button type="submit" class="btn btn-default" name="upload">Confirm</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。