我有一个联系表单,我添加到我的index.jade文件中,我正在尝试使用jade模板中的以下代码向/ route发送一个post请求,该请求呈现正常。
if enquirySubmitted
.row
h3 Thanks for getting in touch.
else
.row
form.contact-form(method="post" )
input(type='hidden', name='action', value='contact')
.col-lg-4.col-sm-4(class=validationErrors.name ? 'has-error' : null)
input.form-control.input-box(type='text', name='name.full', value=formData['name.full'], placeholder='Your Name')
.col-lg-4.col-sm-4
input.form-control.input-box(type='email', name='email', value=formData.email, placeholder='Your Email')
.col-lg-4.col-sm-4
div(class=validationErrors.enquiryType ? 'has-error' : null)
input.form-control.input-box(type='text', name='enquiryType' value=formData.enquiryType)
.col-md-12(class=validationErrors.message ? 'has-error' : null)
.col-md-12
textarea.textarea-box(name='message')= formData.message
button(type='submit') Send Message
这是index.js文件中的on post代码
locals.section = 'contact';
locals.formData = req.body || {};
locals.validationErrors = {};
locals.enquirySubmitted = false;
// On POST requests, add the Enquiry item to the database
view.on('post', { action: 'contact' }, function(next) {
console.log('here');
var newEnquiry = new Enquiry.model(),
updater = newEnquiry.getUpdateHandler(req);
updater.process(req.body, {
flashErrors: true,
fields: 'name, email, phone, message',
errorMessage: 'There was a problem submitting your enquiry:'
}, function(err) {
if (err) {
locals.validationErrors = err.errors;
} else {
locals.enquirySubmitted = true;
}
next();
});
});
我遇到的问题是没有错误或'here'显示在后端收到邮件请求。我一直无法解决这个问题,而且我还需要做些什么才能让联系表格变得有效。看看keystone演示并没有帮助。 index.js文件也位于routes/views/index.js