hi126136
hi126136

Reputation: 31

checkboxes won't submit even when checked

As you can see here, I have the code for checkboxes to modify admin permissions. However, the checkboxes aren't being sent to the server even when they are checked. I can't understand why this is happening. Only the hidden input and the csrf_token is being sent when the submit button is clicked.

<tbody>
                {% for profile in admins %}
                    <tr>
                    <td>{{ profile.player.guid }}</td>
                    <td>{{ profile.user.username }}</td>
                    <form method="post">
                        {% with permissions=profile.admin_permissions_as_list %}
                            {% csrf_token %}
                            <input type="hidden" name="action" value="modify,{{ profile.user }}">
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="ban" {% if permissions.0 == '1' %}checked="checked"{% endif %}></td>
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="unban" {% if permissions.1 == '1' %}checked="checked"{% endif %}></td>
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="checkplayers" {% if permissions.2 == '1' %}checked="checked"{% endif %}></td>
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="viewlog" {% if permissions.3 == '1' %}checked="checked"{% endif %}></td>
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="key" {% if permissions.4 == '1' %}checked="checked"{% endif %}></td>
                            <td style="text-align: center"><input class="form-check-input" type="checkbox" value="faction" {% if permissions.5 == '1' %}checked="checked"{% endif %}></td>
                            <td><button type="submit" class="btn btn-sm btn-outline-primary">修改权限</button></td>
                        {% endwith %}
                    </form>
                    <td>
                        <form method="post">
                            {% csrf_token %}
                            <input type="hidden" name="action" value="remove,{{ profile.user }}">
                            <button type="submit" onclick="return confirmRemove('{{ profile.user.username }}');" class="btn btn-sm btn-outline-danger">取消权限</button>
                        </form>
                    </td>
                    </tr>
                {% endfor %}
        </tbody>

Upvotes: 2

Views: 52

Answers (1)

Quentin
Quentin

Reputation: 943995

You have two major problems.

Upvotes: 3

Related Questions