我正在使用keystonejs提交表单,但是提交时出现错误,提示数据库错误。我如何解决它?。是从表单的模型还是路由文件中获取的?
最初,所有内容都在提交,但现在没有任何效果。我不知道keystonejs版本是否有问题。
routes / contact.js
var keystone = require('keystone');
var Enquiry = keystone.list('Enquiry');
exports = module.exports = function (req, res) {
var view = new keystone.View(req, res);
var locals = res.locals;
// Set locals
locals.section = 'contact';
locals.gamePositions = Enquiry.fields.gamePosition.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();
var updater = newEnquiry.getUpdateHandler(req);
updater.process(req.body, {
flashErrors: true,
fields: 'name, email, phone, address, town, height, weight, dateOfBirth, nameOfFather, fatherTown, fatherPhone, fatherEmail, nameOfMother, motherTown, motherPhone, motherEmail gamePosition',
errorMessage: 'There was a problem submitting your enquiry:',
}, function (err) {
if (err) {
locals.validationErrors = err.error;
} else {
locals.enquirySubmitted = true;
}
next();
});
});
view.render('contact');
};
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Enquiry Model
* =============
*/
var Enquiry = new keystone.List('Enquiry', {
nocreate: true,
noedit: true,
});
Enquiry.add({
name: { type: Types.Name, required: true },
email: { type: Types.Email, required: true },
phone: { type: String },
address: { type: String},
town: { type: String},
height: { type: String},
weight: { type: String},
dateOfBirth: { type: Types.Date},
nameOfFather: { type: Types.Name},
fatherTown: { type: String},
fatherPhone: { type: String},
fatherEmail: { type: Types.Email},
nameOfMother: { type: Types.Name},
motherTown: { type: String},
motherPhone: { type: String},
motherEmail: { type: Types.Email},
gamePosition: { type: Types.Select, options: [
{ value: 'striker', label: 'Striker' },
{ value: 'forward', label: 'Forward' },
{ value: 'midfield', label: 'MidField' },
{ value: 'defender', label: 'Defender' },
{ value: 'goalkeeper', label: 'GoalKeeper' },
] },
createdAt: { type: Date, default: Date.now },
});
Enquiry.defaultSort = '-createdAt';
Enquiry.defaultColumns = 'name, email, gamePosition, createdAt';
Enquiry.register();
我希望感谢您在我们这里注册,但我得到提交您的查询时出现问题:.database错误