3

I have a contact form that I added to my index.jade file and I am trying to send a post request to the / route using the following code in the jade template which renders fine.

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

Here is the on post code in the index.js file

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

});

The problem that I am having is that there are no errors or 'here' being displayed to show that the post request in being received on the backend. I have been unable to solve this and am confused on what else I need to do get the contact form to get working. Looking at the keystone demo didn't help. Also the index.js file is located under routes/views/index.js

TylerH
  • 20,799
  • 66
  • 75
  • 101
Bazinga777
  • 5,140
  • 13
  • 53
  • 92
  • all that code looks right. Perhaps read https://github.com/r3dm/shpe-sfba/blob/master/templates/views/jobForm.jade#L18 & https://github.com/r3dm/shpe-sfba/blob/master/routes/views/jobForm.js#L13 – Harry Moreno Jan 11 '15 at 04:45
  • Thanks,i put it on hold for a while, time to get back to it. – Bazinga777 Jan 12 '15 at 16:42

0 Answers0