pufos pufos - 1 year ago 75
PHP Question

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

I have an online store, and the page

will display user`s purchases like this :

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

The product IDs and Quantities are held in
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
    tag (
    <input id="product1" name="product-1647">

  2. How to iterate through that input if the attribute
    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.

Answer Source


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


foreach ($_POST['product'] as $prod_id => $prod_value){
  if ($prod_value){
    // do whatever
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download