generator-landmark
Version:
A LandmarkJS Project Generator for Yeoman
40 lines (30 loc) • 964 B
JavaScript
var landmark = require('landmark-serve'),
Enquiry = landmark.list('Enquiry');
exports = module.exports = function(req, res) {
var view = new landmark.View(req, res),
locals = res.locals;
// Set locals
locals.section = 'contact';
locals.enquiryTypes = Enquiry.fields.enquiryType.ops;
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) {
var newEnquiry = new Enquiry.model(),
updater = newEnquiry.getUpdateHandler(req);
updater.process(req.body, {
flashErrors: true,
fields: 'name, email, phone, enquiryType, message',
errorMessage: 'There was a problem submitting your enquiry:'
}, function(err) {
if (err) {
locals.validationErrors = err.errors;
} else {
locals.enquirySubmitted = true;
}
next();
});
});
view.render('contact');
};