Form returns empty object in nodejs express

24 Views Asked by At

The form rendered successfully, but the form doesn't return the values as the object. An empty object is returned when why try to fetch the data from the form using console.log(req.body)

Adminjs

router.get('/add-product',function(req,res){
  res.render('admin/add-product')
})
router.post('/add-product',(req,res)=>{
  console.log(req.body);
})

add-product.hbs

<section>
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <h2 class="text-center">Add Product</h2>
                <form action="/admin/add-product" method="POST" enctype="multipart/form-data">
                    <label for="title" class="form-label">Title</label>
                    <input type="text" name="title" class="form-control" id="title">    
                    <label for="price" class="form-label">Price</label>
                    <input type="text" name="price" class="form-control" id="price">
                    <label for="description" class="form-label">Description</label>
                    <input type="text" name="description" class="form-control" id="description">    
                    <label for="image" class="form-label">Image</label>
                    <input type="file" name="image" class="form-control" id="image">    
                    <button type="submit" class="btn btn-success mt-4">Submit</button>
                </form>
            </div>
        </div>
    </div>
</section>

I expecting the data from the form returned when I console res.data

0

There are 0 best solutions below