hi i have a code for submitting a form to database and i am using express.js in that when submitting the form it works well but when i click on the refresh page or F5 the for is re-submitted i need to know how can i solve this issue
1-controller method
static create = async(req,res,next)=>{
try{
let {firstName,lastname,email,phone,username,password,comments,status} = req.body
let user = new Users(firstName,lastname,email,phone,username,password,comments,'inactive');
let [created_user,_] = await user.createUser();
if(created_user){
let insertedID = await created_user.insertId
let [users_info,__] = await user.addUsersInfo(insertedID)
res.render('createuser',{title:'Create User', message:`user created with id : ${insertedID}`})
}
}catch(err){
next(err)
}
}
2-Form
<form class="" action="/users/redirict" method="post" >
<div class="user-insert-rows">
<div class="form-floating mb-3">
<input type="text" class="form-control" id="first-name" name="firstName" placeholder="first name">
<label for="first-name">First Name</label>
</div>
<div class="form-floating">
<input type="text" class="form-control" id="last-name" name="lastname" placeholder="last name">
<label for="last-name">Last Name</label>
</div>
</div>
3-Routers
userRouter.get('/index',newuserController.index)
userRouter.post('/redirict',newuserController.redirict)
userRouter.post('/create',newuserController.create)
What I have tried:
i tried the router by all ways
userRouter.get('/create',newuserController.index)
userRouter.post('/create',newuserController.create)
and at the for action i used
<form class="" action="/users/create" method="post" ></form>