Success and error flash messages on contact form
This commit is contained in:
@ -5,7 +5,8 @@ exports.getContact = function(req, res) {
|
|||||||
res.render('contact', {
|
res.render('contact', {
|
||||||
title: 'Contact',
|
title: 'Contact',
|
||||||
user: req.user,
|
user: req.user,
|
||||||
messages: req.flash('messages')
|
success: req.flash('success'),
|
||||||
|
error: req.flash('error')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -15,13 +16,20 @@ exports.postContact = function(req, res) {
|
|||||||
var email = req.body.email;
|
var email = req.body.email;
|
||||||
var body = req.body.contactBody;
|
var body = req.body.contactBody;
|
||||||
|
|
||||||
|
var sendTo = 'sakhat@gmail.com';
|
||||||
|
var subject = 'API Example | Contact Form';
|
||||||
|
|
||||||
sendgrid.send({
|
sendgrid.send({
|
||||||
to: 'example@example.com',
|
to: sendTo,
|
||||||
from: 'other@example.com',
|
from: email,
|
||||||
subject: 'Hello World',
|
subject: subject,
|
||||||
text: 'My first email through SendGrid.'
|
text: body
|
||||||
}, function(err, json) {
|
}, function(err, json) {
|
||||||
if (err) { return console.error(err); }
|
if (err) {
|
||||||
console.log(json);
|
req.flash('error', err.message);
|
||||||
|
return res.redirect('/contact');
|
||||||
|
}
|
||||||
|
req.flash('success', 'Email has been sent successfully!');
|
||||||
|
res.redirect('/contact');
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -25,7 +25,9 @@ block content
|
|||||||
i.fa.fa-location-arrow
|
i.fa.fa-location-arrow
|
||||||
| Send
|
| Send
|
||||||
button.btn.btn-link(disabled='') Powered by SendGrid
|
button.btn.btn-link(disabled='') Powered by SendGrid
|
||||||
if messages.length
|
if error.length
|
||||||
.alert.alert-danger
|
.alert.alert-danger
|
||||||
for message in messages
|
p= error
|
||||||
div= message
|
if success.length
|
||||||
|
.alert.alert-success
|
||||||
|
p= success
|
||||||
|
Reference in New Issue
Block a user