I am not sure how to submit data to my update form and what I have to put in the action field as the router.post has an :id. Below is my code:
router.post('/gymupdate/:id',async(req,res) => {
let gymName = req.body.firstname;
let location = req.body.city;
let phoneNumber = req.body.mobile;
let priceRange = req.body.price;
let id = req.params.id;
try{
check2(gymName,location,phoneNumber,priceRange);
if(!id) throw 'Pleaase provide an id';
var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
if(checkForHexRegExp.test(id)===false) throw 'Not a valid objectid';
const updategym = await gymData.update(id,gymName,location,phoneNumber,priceRange)
if(updategym)
res.status(200).redirect('/gyms')
else {
res.status(500).render('gymbars/updategym', {title: "Error", error: 'Internal Server Error'})
}
}
catch(e){
res.status(400).render('gymbars/updategym', {title: "Error", error: e})
}
});
Form:
<form method="POST" action="/gyms/gymupdate/:id" id="signup-form" class="signup-form"></form>
The content in the action does not work, so how do I add id field to the action part similar to the router.post method?