I researched a lot on how to do this and could not answer. Here's the situation: I have a listById method that needs to get the id that comes in the URL through the form. It turns out that when I submit the form, it forwards to the URL that is in the action +? Id = # o_que_o_usuario_digitado #. Hence my route manager can not handle this.
HTML:
<form class="container" action="/listById/" method="GET">
<input class="form-control" type="text" name="id" id="id">
<button id="btn-search" class="btn btn-primary" type="submit">Search</button>
</form>
Route Manager:
app.get('/listById/:id', controlcontact.listById);
METHOD called in route:
contact.listById = (req,res)=>{
request.get(externalApi+req.params.id,
(error, response, body) => {
res.render('listById',{
contact: JSON.parse(body)
})
});
}
Example: if the input is typed "12345", the submit forwards to "/ listById /? id = 12345" I wanted to resolve this just by using HTML, without having to create javascript function.