发送多个复选框选项 [英] Sending multiple checkbox options
问题描述
我正在创建一个二手车网站(用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屋!