dqhnp44220 2010-04-17 23:42
浏览 23
已采纳

发送多个复选框选项

I'm creating a used cars website (written in PHP), and I'm stuck on sending advanced search options from form. I have more than 30 of them and I wonder if it's possible, and how, to send them in one variable (for example &options=1,2,3,5,6,10 or some other way..).

Also I've heard that this is possible with "bitwise" but I don't have a clue how to do that. Or if someone have a better idea, please let me know.

Thanks.

  • 写回答

5条回答 默认 最新

  • dongtang4019 2010-04-17 23:57
    关注

    You can send them in an array.

    <form method="post">
        <input type="checkbox" name="param[]" value="blue" />
        <input type="checkbox" name="param[]" value="red" />
        <input type="checkbox" name="param[]" value="orange" />
        <input type="checkbox" name="param[]" value="green" />
        <input type="checkbox" name="param[]" value="black" />
        <input type="submit" value="Submit" />
    </form>
    
    >> $_POST['param']
    array('blue', 'orange')
    

    You can even use multidimensional arrays:

    <form method="post">
        <input type="checkbox" name="param[color][]" value="blue" />
        <input type="checkbox" name="param[color][]" value="red" />
        <input type="checkbox" name="param[color][]" value="orange" />
        <input type="checkbox" name="param[color][]" value="green" />
        <input type="checkbox" name="param[color][]" value="black" />
        <input type="checkbox" name="param[year][]" value="1999" />
        <input type="checkbox" name="param[year][]" value="2000" />
        <input type="checkbox" name="param[year][]" value="2001" />
        <input type="checkbox" name="param[year][]" value="2002" />
        <input type="checkbox" name="param[year][]" value="2003" />
        <input type="submit" value="Submit" />
    </form>
    
    >> $_POST['param']['color']
    array('blue', 'green')
    
    >> $_POST['param']['year']
    array('2001', '2004')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制