我有一个页脚,它是部分页脚,其中包含“订阅新闻稿”表格。我需要将表单发送回服务器的请求,以便服务器验证数据以确保用户输入了正确的数据,并将错误或成功消息返回到页脚部分。到目前为止,这是我的代码
<div class="form-group">
<h3>Subscribe</h3>
<form class="form-inline" action="/" method="post">
<input type="email" class="form-control" id="footerForm" name="footerEmail" placeholder="Email">
<button>Subscribe</button>
<p>{{errMsg}}</p>
</form>
</div>
app.post("/", (req, res) => {
console.log(req.body.footerEmail);
if (!req.body.footerEmail) {
res.render("/", { errMsg: "please add an email" });
} else {
const newEmail = {
footerEmail: req.body.footerEmail
};
new newsletterEmail(newEmail).save();
res.render("/", { sucessMsg: "please add an email" });
}
});