HTML form checkboxes not submitting as I expect

[Solution: change my names to arrays by concatenating "[]" to the end. Also, change my IDs to unique values ​​to match the HTML specs]

I am creating a form that has a table (html table) from checkboxes with one user per row and user permissions on columns. Each cell has a checkbox. Each checkbox in the row has a "name" set to the user's email address (unique). Checkbox values ​​are specific permission identifiers. when I click the submit button and check the parameters that I return from the HTTP POST, only the rightmost checkbox is set for lines that are marked with multiple blocks.

For example, there are three checkboxes, the first and second are checked, the third is unchecked. I am only returning the name = id of this second checkbox.

I am creating a form in Rails, although I don't think this is really relevant. Also, the browser giving this behavior is Chrome, Iceweasel and Epiphany ... So I think this is my form.

An excerpt from 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>

      

+3


source to share


3 answers


You set name = "" on all of them to be the same, so it will replace whatever value was originally there when you checked more than one checkbox.



Or give each checkbox a different name, for example. name="one@oreo.com_check_1"

or include them in an array with name="one@oreo.com[]"

. Then all the values ​​passed to it in an array will be saved, which you can process after submitting the form!

+5


source


Your checkbox names must be unique. I suggest puttitempeh user id and permission id in the name. Also you have to change Ida accordingly. Ids do not affect form submission, but it is wrong to have multiple elements with the same ID in HTML.



0


source


You cannot say the name parameter is the same for every line. Checkboxes must be unique, or at least an array. The radio buttons are where you should use the same name.

0


source







All Articles