2

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>
bruno desthuilliers
  • 68,994
  • 6
  • 72
  • 93
hi126136
  • 31
  • 5

1 Answers1

3

You have two major problems.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
  • Thanks, name seemed to be what I needed! I thought it would be value lol since a lot of the examples used values. – hi126136 Feb 10 '20 at 17:01
  • @hi126136 — The `name=value` pair needs a name **and** a value (although checkboxes will use a default value of On) – Quentin Feb 10 '20 at 17:02