How to submit only the quantity of the products that were selected in the checkbox?

0

Show an item table and in this table I added a checkbox for each item and a field to pick up the quantities for each item.

I'm able to send only the checked items in the checkbox (that's what I wanted) to PHP.

But I can not do the same with the quantity, as I am sending via POST the quantity of all the items in the table, both the items that were selected and those that were not.

I want to send the quantity only of the selected items, or who knows how to continue sending it like this and then sort the array in PHP by eliminating the empty quantities.

How could I solve this?

    
asked by anonymous 09.06.2018 / 03:40

1 answer

0

Instead of using foreach, you would use a for with a $i counter that would be incremented by 1. This value of $i would go to the value of your checkbox. So you would have the position of it in your table.

I would add an input hidden for each row in the table that would hold the $item['id'] information.

So, you would have the indexes that were filled in the $ quantity vector, being able to retrieve the quantity of the products and in the hidden input the ids of the products.

I do not know if this is the best solution, but it was the one that came to mind right now.

    
09.06.2018 / 04:31