Multiple Forms or Multiple Submits in a Page?

后端 未结 1 955
孤城傲影
孤城傲影 2020-11-28 06:05

I\'m creating a page with the products sold in the website. I\'d like to include an \"add to cart\" button near each product, which are listed with markup similar to this:

1条回答
  •  萌比男神i
    2020-11-28 06:31

    Best practice: one form per product is definitely the way to go.

    Benefits:

    • It will save you the hassle of having to parse the data to figure out which product was clicked
    • It will reduce the size of data being posted

    In your specific situation

    If you only ever intend to have one form element, in this case a submit button, one form for all should work just fine.


    My recommendation Do one form per product, and change your markup to something like:

    This will give you a much cleaner and usable POST. No parsing. And it will allow you to add more parameters in the future (size, color, quantity, etc).

    Note: There's no technical benefit to using

    0 讨论(0)
提交回复
热议问题