Home > Back-end >  am adding inputs from the form page but the console shows only the email and other elements calls un
am adding inputs from the form page but the console shows only the email and other elements calls un

Time:07-06

const express = require('express')
var bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
const port = 3000
app.use(express.static("public"));

app.get('/', function(req ,res) {
res.sendFile(__dirname  "/singup.html")
})
app.post("/", function(req , res){
    var firstName = req.body.firsName;
    var lastName = req.body.lastName;
    var email = req.body.email;
    console.log(firstName, lastName , email );
    
})


app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

  <body >
    
<main >
 <form action="/"  method="post">
    <img  src="imgs/logo.png" alt="" width="72" height="57">
    <h1 >Please sign in</h1>
    <input type="text" name="fName"  placeholder="first name">
    <input type="text" name="lName"   placeholder="last name">
    <input type="email" name="email"   placeholder="Email">
    <button  type="submit">Sign me up</button>
    <p >&copy; heersan</p>
  </form>
</main>


    
  </body>
</html>

 
   

<!-- begin snippet: js hide: false console: true babel: false -->

and this form when I add the First name and last name and email the terminal logs only email and makes first-name and Lastname undefined .it logs on the email not there other elements

CodePudding user response:

Typo alert !

The attribute names are fName and lName, not firstName/lastName :

var firstName = req.body.fName;
var lastName = req.body.lName;
var email = req.body.email;
console.log(firstName, lastName, email );

Cheers

  • Related