[Solution: Change my names to arrays by concatenating “[]” to the end. Also, change my IDs to be unique values to conform to HTML specifications]
I’m creating a form, that has a matrix (html table) of checkboxes with one user per row, and user permissions on the columns. Each cell has a checkbox. Each checkbox in a row has the “name” set to the user’s email address (unique). The values of the checkboxes are the IDs of the particular permission. when I click the submit button, and inspect the params I get back from the HTTP POST, only the right-most checkbox is set for rows that have multiple boxes checked.
For example, there are three checkboxes, first and second checked, third unchecked. I only get back the name=id of that second checkbox.
I’m building the form in Rails, although I don’t believe that to be relevant really. Also, the browser that’s giving this behavior is Chrome, Iceweasel, and Epiphany… So I think it’s my form.
An excerpt of my form:
<tr>
<td>UserOne</td>
<td>one@oreo.com</td>
<td>
<input checked="checked" id="one_oreo.com" name="one@oreo.com" type="checkbox" value="1" />
</td>
<td>
<input id="one_oreo.com" name="one@oreo.com" type="checkbox" value="2" />
</td>
<td>
<input id="one_oreo.com" name="one@oreo.com" type="checkbox" value="3" />
</td>
<td>
<input checked="checked" id="one_oreo.com" name="one@oreo.com" type="checkbox" value="4" />
</td>
<td>
<input id="one_oreo.com" name="one@oreo.com" type="checkbox" value="5" />
</td>
<td>
<input id="one_oreo.com" name="one@oreo.com" type="checkbox" value="6" />
</td>
</tr>
You have set the name=”” on all of them to the same thing, so it is going to replace whatever value was originally there when you tick more than one checkbox.
Either give each checkbox a different name e.g.
name="one@oreo.com_check_1"or turn them in to an array usingname="one@oreo.com[]"This will then store all values passed to it in an array that you can then process after the form has been submitted!