-1

This is kinda part two of my "duplicate" here: Why does this multiple row table submit by row? Is this correct?

I modified the original code:

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

to:

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

When reading the post I expected to see a $_POST (php) array containing two main indexes:

 ['first'] => Array([1] => 'mark', [2] => 'luke', [3] => 'john'),
 ['editbutton'] => Array([1] => '1', [2] => '2', [3] => '3')

This is not what I got. The 'name' index was properly constructed, but the submit button index 'editbutton' contained only one element, the value of the button pressed. I'd like to count on this but is this correct or am I again counting on the current server's behavior?

Thanks. Sorry if I'm beating a dead horse here.

Community
  • 1
  • 1
user116032
  • 321
  • 2
  • 15
  • I got a tumbleweed award for this one! Anyway, I think this is a legit question. I followed the instructions given and created arrays and I'm surprised by the result. I read the spec that seem to apply but it's over my head. Please, is it official, that arrayed submit buttons that don't fire are "null" and unsent? – user116032 Jul 25 '16 at 20:33

2 Answers2

0

Add a click event listener to the table. Use JavaScript, push values of this and siblings into array and POST it. If issues look into event bubbling. Don't forget to include the (e) event arg in your listener.

Don't use a form with input type="submit". Use vanilla XHR. trigger it with click event listener.

xhttp.open("POST", "ajax_test.asp", true);

xhttp.send("fname=Henry&lname=Ford");

Community
  • 1
  • 1
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
  • I actually use jquery to motor this table, but I want to know if the population of the submit buttons array is standard behavior. – user116032 Jul 26 '16 at 00:30
  • You don't need a button just click row. But if you want button `getElementsByTagName('button')` on table to get buttons index. Then you have index # of row to grab data. Don't need to hardcode [1], [2], etc. Use method I mentioned which give you an array. – Ronnie Royston Jul 26 '16 at 00:32
0

As to your question, I think you can count on it. Refer to the page at http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_button_name Two buttons are provided on the form but only one value is received on the server side each time you submit the form. So at least PHP and ASP accept only one submit button value as far as I know. But from the accepted answer of this question How $_POST works and https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data

We can see that it is actually defined by browsers, which means that the data sent out from browser does not actually include any other submit button value. So I think I an safely assume that all other language will not receive second submit button value because it never sent out from your web browser.

Community
  • 1
  • 1
lhrec_106
  • 630
  • 5
  • 18