1

Here's a snip of table code found within a form. The rows are "identical". The inputs are all named alike. The submit buttons are all named alike. Each row contains <input> elements and each row has one submit button.

<tr>
   <td><input type='text' name='first' value='mark'></td>
   <td><td><button type='submit'name='editbutton' value='1'>Edit</button></td>
</tr>
<tr>
   <td><input type='text' name='first' value='luke'></td>
   <td><td><button type='submit'name='editbutton' value='2'>Edit</button></td>
</tr>
<tr>
   <td><input type='text' name='first' value='john'></td>
   <td><td><button type='submit'name='editbutton' value='3'>Edit</button></td>
</tr>

When a button is pressed, $_POST contains the data in the same row as the submit button. It works in ie and ff. Is this how this is supposed to work? I've use javascript/jQuery with id's to collect specific rows of data in the past, but if this submit construct, which does work, is correct, I'd use it instead.

Thank you.

user116032
  • 321
  • 2
  • 15
  • So what you want is to get data from every row, like an array of your data, right ? – tektiv Jul 14 '16 at 14:40
  • No. I just want data from one row. It is operating "correctly". I just want to know if I've lucked out or not. As stated above, I've had to use javascript and IDs to pluck out rows in the past. – user116032 Jul 14 '16 at 15:59

1 Answers1

0

As stated in another question on SO (relative since it is about hidden inputs) :

The browsers are OK with it. However, how the application library parses it may vary.
Programs are supposed to group identically named items together. While the HTML specification doesn't explicitly say this, it is implicitly stated in the documentation on checkboxes.

So this is just pure luck : Working with another server-side technology may get you another result.

For more information about what you could get, check this answer on another question. It has a lot of useful information and specs.


Besides, if you wanted to get all the values of name="first", you would better name them like name="first[]".

Then you will have on the server $_POST["first"] as an array you can loop through.

Community
  • 1
  • 1
tektiv
  • 14,010
  • 5
  • 61
  • 70