-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontactUs.js
48 lines (36 loc) · 1.01 KB
/
contactUs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
// specifying schema of the database
const formSchema = new mongoose.Schema(
{
data: Object,
},
{ collection: "survey_form" }
);
const Form = mongoose.model("Form", formSchema)
const formData = (bodyData) => {
Form({ data: bodyData }).save((err) => {
if (err) {
throw err;
}
})
}
router.get('/:success?', (req, res) => {
let success = req.params['success'];
console.log(success);
if(success === undefined){
res.render('contactus', {msg:null});
}else{
res.render('contactus', {msg:"We've received your feedback! Thank you."});
}
})
router.post('/post', function (req, res) {
console.log(req.body);
res.redirect('/contactus/success');
formData(req.body);
});
module.exports = router;