nanakumi75 16 Newbie Poster

I hope someone can understand my question and offer some help. I am creating a Flight Booking application with Amadeus APIs. I have a flight search form on the index page with hbs template engine.

The form submits to /auth/flights for processing. I then want to display all error in index page (if there are any).

But the problem is that, maybe due wrong linking, I can't get the form to display all errors back to the index page. I will display my code below so that you can see what I mean.

//flight search form in index.hbs

    <form action="/auth/flights" method="post">
      input details here
    </form>

//in server.js
app.use('/',require('./routes/pages');
app.use('/auth',require('./routes/auth');


//auth.js @ routes/auth
const express = require('express');
const router = express.Router();
const authController = require('../controllers/auth');

router.post('/',authController.flights);
module.exports = router;

//in auth.js @ controllers/auth
exports.flights = function(req,res){
  const {location,destination,depart} = req.body;

  if(!location || !destination || !depart){
  res.status(404).render('/',{error:'Fields marked are required'});
 }
}

My problem is that, I can't reload the index page. I will be happy if someone can offer some advice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.