Node.js 使用nodejs在mongodb数据库中保存隐藏类型数据时出错
我在表单中有两个东西,第一个是添加密码,另一个是id,它不需要输入,因为当我单击add时,它直接来自数据库。我得到了一个错误 Post方法是Node.js 使用nodejs在mongodb数据库中保存隐藏类型数据时出错,node.js,mongodb,ejs,Node.js,Mongodb,Ejs,我在表单中有两个东西,第一个是添加密码,另一个是id,它不需要输入,因为当我单击add时,它直接来自数据库。我得到了一个错误 Post方法是 router.post('/', checkLogin, function (req, res, next) { var user = localStorage.getItem('loginname'); var add_model = new pass_cat({ password: req.body.catename,
router.post('/', checkLogin, function (req, res, next) {
var user = localStorage.getItem('loginname');
var add_model = new pass_cat({
password: req.body.catename,
user_id: req.body.id
})
add_model.save(function (err, doc) {
if (err) throw err;
res.render('AddCategory', {
title: 'Password Management System',
user: user,
msg: 'Inserted Successfully'
})
})
});
表单的ejs代码是
<form action="/add_category" id="EmployeeForm" class="form-horizontal" method="post" role="form">
<input type="hidden" name="id" value="<%= data%>" >
<div class="form-group">
<label for="Username" class="col-md-3 control-label">Add Category Name</label>
<div class="col-md-9">
<input type="text" class="form-control" name="catename" placeholder="Enter Password Category">
</div>
</div>
<div class="form-group">
<label for="User_id" class="col-md-3 control-label">User_id</label>
<div class="col-md-9">
<input type="text" class="form-control" name="userid" value="<%=data[0]._id%>" placeholder="Enter Password Category">
</div>
</div>
添加类别名称
用户id
表单中不需要这一行,因为您没有在任何地方设置数据,其值也没有定义。
表单中不需要这一行,因为您没有在任何地方设置数据,也没有定义其值。您是否可以在问题描述中添加错误?表单中不需要这一行,因为您没有在任何地方设置数据,其值也没有定义。@VishwadeepKapoor通过您的评论,我的问题没有得到解决,但我已经有了这样做的想法,非常感谢您,所以muchthanks@Rajatsharma将评论转换为答案。您是否可以在问题描述中添加错误?表单中不需要这一行,因为您没有在任何地方设置数据,其值也没有定义。@VishwadeepKapoor通过您的评论,我的问题没有得到解决,但我已经有了这样做的想法,非常感谢您将评论转换为答案。
<input type="hidden" name="id" value="<%= data%>" >