开发者

php form process - unknown input names for quantity increase / decrease

I have an onli开发者_StackOverflow社区ne store, and the page mycart.php will display user`s purchases like this :

image - title - price per unit - quantity - total price

The product IDs and Quantities are held in $_SESSION arrays. (Is this good ?)

So if the user want 2 pieces of one product and 3 pieces of another product:

  1. How to generate the <input> tag (<input id="product1" name="product-1647">?)
  2. How to iterate through that input if the attribute name="product-1647" is dynamic generated?

I've studied a website and they generate inputs like above.

<input type="text" id="product1" name="product-23342">
<inpyt type="text" id="product2" name="product-47385">
...

But i can't figure it out how the post-processing is done.

Any advice will be great.


html

<input type="text" id="product1" name="product[23342]">
<inpyt type="text" id="product2" name="product[47385]">

php

foreach ($_POST['product'] as $prod_id => $prod_value){
  if ($prod_value){
    // do whatever
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜