代码之家  ›  专栏  ›  技术社区  ›  Toniq

php形成多个复选框组

  •  0
  • Toniq  · 技术社区  · 7 年前

    我在from中有一组复选框,需要用php获取值。注意,div类=“组”也可以用jQuery(带jQuery)进行复制,所以我可能以复选框的多个“类=”组结尾。

    是否有方法设置复选框名称,以便将每个“组”的表单数据分组在一起,或者以后更容易处理的内容?还有一个问题是没有选中复选框,因此它们不会出现在post数据中。

    我试着用这样的名字,但我不喜欢结果。

    <form>
        <div class="group">
            <input type="checkbox" name="ev[][time]">
            <input type="checkbox" name="ev[][space]">                 
            <input type="checkbox" name="ev[][money]">
        </div>
    
        <div class="group">
            <input type="checkbox" name="ev[][time]">
            <input type="checkbox" name="ev[][space]">                 
            <input type="checkbox" name="ev[][money]">
        </div>
    </form>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   marc_s MisterSmith    6 年前

    在定义复选框组时,最好详细说明输入名称,并避免使用 [] 表示法。

    未勾选的复选框不会在POST数据中发送,您的选择将变为未对齐。

    <form>
        <div class="group">
            <input type="checkbox" name="ev[0][time]">
            <input type="checkbox" name="ev[0][space]">                 
            <input type="checkbox" name="ev[0][money]">
        </div>
        <div class="group">
            <input type="checkbox" name="ev[1][time]">
            <input type="checkbox" name="ev[1][space]">                 
            <input type="checkbox" name="ev[1][money]">
        </div>
        <div class="group">
            <input type="checkbox" name="ev[2][time]">
            <input type="checkbox" name="ev[2][space]">                 
            <input type="checkbox" name="ev[2][money]">
        </div>
    </form>
    
    推荐文章