Home > Mobile >  I have to pass a name from an input form in my ejs file and handle it in my post request
I have to pass a name from an input form in my ejs file and handle it in my post request

Time:11-28

I have an ejs file where i want the user to enter into the form an username which i will then use in my .get request to do some logic, but my usename isnt correctly being got its showing as undefined.

index.ejs:

<form action="/entry" method="GET">
  <label>Enter Name <input  type="text" name="name"></label>
  <input  type="submit" value="index" >
</form>

enrty.js where i have my get request:

router.get("/entry" , async(req, res) => {
  const allEntries = await  dailyUsage.find();

  const {name} = req.body;
  console.log(name);

  // ...
}

I want ̀name` to contain the username entered from the form, but without using bodyparser or middleware. thank you

CodePudding user response:

Since your form is using GET method, you won't find name in req.body, but in req.query:

const {name} = req.query;
  • Related