I'm learning Node.js with Express. I'm doing some basic form validation. If it fails, I'd like to reload the page with same view showing the errors. For the validation I'm using express-validator.
I am able to display the errors and the same view, but the URL is not that one belonging to the view that has the form, but that one called by the POST request. I'd like to be redirected to the form view with the messages though.
This is my code so far
// process form to add ideas
app.post('/ideas', (req, res) => {
req.checkBody('details', 'Details are required').notEmpty();
var errors = req.validationErrors();
if (errors) {
res.render('ideas/add', {
title: 'Add Ideas',
errors: errors
});
} else {
res.send('ok');
}
});
So, even if I render back the view "ideas/add"... the URL is going to be "/ideas"... but I'd like it were "ideas/add" too.
Any ideas?
Thanks