I am creating a page with products sold on a website. I would like to add an โadd to cart" button next to each product that is listed with markup like this:
<h4 class="productHeading">Product Name 1</h4> <div> Extra information on the product 1. </div> <h4 class="productHeading">Product Name 2</h4> <div> Extra information on the product 2. </div> ...
Since the input for sending will have different names (with the product code included), the big question is: should I wrap the entire list of products in the form or create one form for each product? In code:
<form method="post" action="process.php"> <h4 class="productHeading">Product Name 1</h4> <div> Extra information on the product 1. <input type="submit" name="submit1" value="Add to Cart"> </div> <h4 class="productHeading">Product Name 2</h4> <div> Extra information on the product 2. <input type="submit" name="submit2" value="Add to Cart"> </div> </form>
Or...
<h4 class="productHeading">Product Name 1</h4> <div> Extra information on the product 1. <form method="post" action="process.php"> <input type="submit" name="submit1" value="Add to Cart"> </form> </div> <h4 class="productHeading">Product Name 2</h4> <div> Extra information on the product 2. <form method="post" action="process.php"> <input type="submit" name="submit2" value="Add to Cart"> </form> </div>
Which one is best practice? Any serious reason not to use one or the other, or am I doing this completely wrong?
html submit forms
winck Jan 03 2018-12-12T00: 00Z
source share