Вопрос

Let's assume a page has a bunch of submit buttons that are generated by a PHP loop of some kind. They are named after the loop value, so the result would look something like this:

<input type="submit" name="0" id="0" value="click me">
<input type="submit" name="1" id="1" value="click me">

etc.

Let's say that there could be anywhere between zero and a gazillion of these buttons. Assuming that the form is POST, how would I identify, on the page that loads afterward, which of the buttons had been clicked?

Это было полезно?

Решение

As I mentioned in the comments above, you would be better to use an array in the HTML:

<form action="" method="post">
<?php
for ($i = 0; $i < 100 ; $i++) {
    echo '<input type="submit" name="clicked['.$i.']" value="clicked" />';
}
?>
</form>

Then in your PHP you can get the clicked input by doing:

echo key($_POST['clicked']); // Prints, for example, 28
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top