Right now I have a POST form submission working, on my home page, for signing up someone for a mailing list. Now I'm trying to figure out how to "confirm" the success of the signup. Here is the post code:
// handle a signup submission
app.post('/signup', function(req, res) {
// create the signup email message
const message = {
to: 'contact@example.com',
from: req.body.email,
subject: 'Example.com signup',
text: req.body.email + ' has been subscribed'
}
// send the email and handle any errors
sendgrid.send(message, function(err, result) {
// handle errors
});
// redirect back to the original page
res.redirect('/');
});
Is there a way to communicate a message to my home page so that I could, for example, have a pop-up appear for a few seconds ("Subscription successful!") or something to that effect?
My home page is an index.html file. I'm open to converting it over to .ejs file if necessary.
The top answer here looks like it could work: How do I use req.flash() with EJS? . Is that the "right" way of doing it?