首页 > 解决方案 > 复选框即使选中也不会提交

问题描述

正如您在此处看到的,我有用于修改管理员权限的复选框的代码。但是,即使选中复选框,它们也不会发送到服务器。我不明白为什么会这样。单击提交按钮时,仅发送隐藏的输入和 csrf_token。

<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>

标签: html

解决方案


你有两个主要问题。


推荐阅读