3

我有一个添加到我的 index.jade 文件的联系表单,我正在尝试使用翡翠模板中的以下代码向 / 路由发送一个发布请求,该代码可以很好地呈现。

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();
    });

});

我遇到的问题是没有错误或显示“此处”以显示后端收到的发布请求。我一直无法解决这个问题,并且对我还需要做什么才能让联系表开始工作感到困惑。查看 keystone 演示并没有帮助。index.js 文件也位于routes/views/index.js

4

0 回答 0