发送多个复选框选项 [英] Sending multiple checkbox options

查看:130
本文介绍了发送多个复选框选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个二手车网站(用PHP编写),并且我坚持从表单发送高级搜索选项。我有超过30个,我想知道是否有可能以及如何将它们发送到一个变量中(例如& options = 1,2,3,5,6,10 或其他方式..)。

另外我听说这是可能的按位,但我没有线索如何去做。或者如果有人有更好的主意,请让我知道。



谢谢。 您可以将它们发送到数组中。

 < form method =post> 
< input type =checkboxname =param []value =blue/>
< input type =checkboxname =param []value =red/>
< input type =checkboxname =param []value =orange/>
< input type =checkboxname =param []value =green/>
< input type =checkboxname =param []value =black/>
< input type =submitvalue =Submit/>
< / form>

>> $ _POST ['param']
array('blue','orange')

您甚至可以使用多维数组:

 < form method =post> 
< input type =checkboxname =param [color] []value =blue/>
< input type =checkboxname =param [color] []value =red/>
< input type =checkboxname =param [color] []value =orange/>
< input type =checkboxname =param [color] []value =green/>
< input type =checkboxname =param [color] []value =black/>
< input type =checkboxname =param [year] []value =1999/>
< input type =checkboxname =param [year] []value =2000/>
< input type =checkboxname =param [year] []value =2001/>
< input type =checkboxname =param [year] []value =2002/>
< input type =checkboxname =param [year] []value =2003/>
< input type =submitvalue =Submit/>
< / form>

>> $ _POST ['param'] ['color']
array('blue','green')

>> $ _POST ['param'] ['year']
array('2001','2004')


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.

解决方案

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

这篇关于发送多个复选框选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆