确定在使用按钮数组时单击了哪个“提交”按钮

I have a script which generates a table containing numerous rows and coloumns. On each end of a row, is a Submit button, whose name is one of an array generated on running the script, and goes like: delete_CN[0], delete_CN[1] etc.

While processing the form POST, I need to determine which Submit button was clicked. Currently, when I see a print_r or dump_vars, I see the following: ["delete_CN"]=> array(1) { [0]=> string(6) "Delete" }, which does not give the array index of the button that was pressed.

How should I best go about doing this? I need to find the array index of the submit button which was pressed, or another way to uniquely identify the row of the Submit button, to process the data. The original form is dynamically generated by reading a zonefile, and the elements on the same row are all arrays.

the post data will always include all buttons but only the one which was clicked will have a value. this way you can determine easily which button was clicked by checking which value in the button array is not empty. (The value will be the text on the button as that text is defined in the value attribute).

In HTML/PHP you could make each row in the table a seperate form, and add a

<input type="hidden" name="which_clicked" value="delete_CN[0]">

then look for $_POST['which_clicked']

or you could use jQuery and have a which value is inserted based on which submit button is clicked.

Be aware that a form can also be submitted using the ENTER key. In case this happens the browser handles it like the first button in the form was clicked.

Obviously, pressing ENTER when focus is on a submit-button sends the form using this currently focused button.

What I do, I create an array of input type hidden, with "unique value", and those value we assigned to each button. such as input type = "hidden" name = "txtID[]" id = "txtID[]" value = "15618" and for the button input type="submit" name="CityAdd15618" id="CityAdd15618" value="+"

then when submit, you just need to loop

$lTtl=count($_POST['txtID']);
for($lCtr1=0; $lCtr1<$lTtl; $lCtr1++)
{
    if (isset($_POST['CityAdd' . $_POST['txtID'][$lCtr1]]))
        break;
}
echo "ttl:" . $lCtr1 . "<br>
";