Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form with multiple submit options

I'm trying to create a small web app that is used to remove items from a MySQL table. It just shows the items in a HTML table and for each item a button [delete]:

item_1 [delete]
item_2 [delete]
...
item_N [delete]

To achieve this, I dynamically generate the table via PHP into a HTML form. This form has then obviously N [delete]-buttons. The form should use the POST-method for transfering data.

For the deletion I wanted to submit the ID (primary key in the MySQL table) of the corresponding item to the executing php skript. So I introduced hidden fields (all these fields have the name='ID' that store the ID of the corresponding item.

However, when pressing an arbitrary [delete], it seems to submit always just the last ID (i.e. the value of the last ID hidden field).

Is there any way to submit just the ID field of the corresponding item without using multiple forms? Or is it possible to submit data from multiple forms with just one submit-button? Or should I even choose any completly different way?

The point why I want to do it in just one single form is that there are some "global" parameters that shall not be placed next to each item, but just once for the whole table.

like image 569
phimuemue Avatar asked Nov 23 '25 14:11

phimuemue


1 Answers

<input type="submit" name="delete[1]" value="delete">

if (isset($_POST['delete'])) $id=key($_POST['delete']);
like image 99
Your Common Sense Avatar answered Nov 26 '25 04:11

Your Common Sense



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!