【发布时间】:2020-12-31 09:08:07
【问题描述】:
我有两件事,第一个是添加密码,另一个是id,不需要输入,因为它直接来自数据库,当我点击添加时出现错误
post方法是
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>
【问题讨论】:
-
能否在问题描述中也添加错误?
-
表格中不需要这一行,因为您没有在任何地方设置数据,并且它的值没有定义。
-
@VishwadeepKapoor 通过您的评论,我的问题并没有解决,但我有了这样做的想法,非常感谢
-
感谢@Rajatsharma 将评论转换为答案。