javascript - 无法使用节点 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>
解决方案
推荐阅读
- c# - 如何为 wpf 应用程序存储共享文件和图像
- python - 惩罚 Python PuLP 优化函数,因为决策变量偏离特定常数
- reactjs - 如何将自定义样式添加到样式组件?
- android - 在 Android (Qualcomm Adreno 630) 上链接 OpenCL 内核时的 SIGABRT
- python - 如何创建一个函数来检查 wincon for connect 4?
- javascript - 页面重新加载后保留文本框上的值
- python - 将 json 文件反序列化为对象数组
- python - 在 python 中使用两个循环的问题
- r - R Pathview 功能 - 无法查看 KEGG 通路上的基因符号
- node.js - Api拦截器重试不从承诺返回数据