After retrieving a list of products from a database, everything seems to be functioning properly. However, I am facing an issue when trying to capture the ID when a user clicks on the 'Buy' button. Despite multiple attempts to save the req.body data, I have been unsuccessful.
I experimented with SessionStorage and LocalStorage options, but unfortunately, they did not yield any positive results.
carritoForm: (req, res) => {
let obj = JSON.parse(JSON.stringify(req.body)); // req.body = [Object: null prototype] { title: 'product' }
console.log(obj)
res.redirect('index');
}
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 bloques">
<p>Incendios</p>
<div class="imagen">
<a href="" target="_blank"><img src="../images/fire.png" alt="" /></a>
</div>
<br>
<p>Lorem ipsum dolor sit amet consectetur adipiscing elit elementum eget congue, tristique sollicitudin enim eu
nisi ultrices iaculis justo scelerisque, phasellus vestibulum metus rhoncus sapien a integer odio ligula.
Senectus parturient maecenas conubia netus pharetra felis placerat tincidunt, tortor fusce cras ligula nostra
cursus augue duis lacinia, nascetur semper a habitasse euismod inceptos vivamus. Sociosqu ante neque morbi
pulvinar habitasse enim himenaeos, ultrices per orci molestie nisi fames dignissim praesent, lacus iaculis class
cursus mollis eros.</p>
</div>
</div>
<div class="container">
<div class="row">
<br>
<% products.filter(function (el) { %>
<% return (el.prdCategId === 3); %>
<% }).map(function(el) { %>
<br>
<div class="col-sm-12 col-md-12 col-lg-12 lista-productos">
<div class="col-sm-4 col-md-4 imgcart">
<img src="/images/prdImages/<%= el.image %>" alt="">
</div>
<br>
<div class="col-sm-8 col-md-8 agregar-carrito">
<br>
<b>Descripcion:</b> <%= el.description %> <br>
<b>Precio: $</b> <%= el.price %> <br> <br>
<form name= 'compras' action="/products/incendios" method="POST" >
<button name="incendios" value="<%= el.id %>" type="submit">Buy</button>
</form>
<br>
<br>
</div>
</div>
<% }).sort(); %>
</div>
</div>
</div>
Upon clicking 'Comprar,' the output correctly displays '{ incendios: '2' }', which corresponds to the pressed button. However, I am unsure about how to store this information.