HTML复选框表单和HTTP URL [英] HTML checkbox form and HTTP URL
问题描述
所以,我有这个HTML表单:
So, I have this HTML form:
<form id="search_form" class="form_wrapp"
accept-charset="utf-8" method="get" action="http://testing.com/results">
<input class="inputbox" type="text" name="search_query">
<input class="ic_search" type="submit" value="">
<input type="checkbox" value="checkbox1" name="search_filter[]">
<label for="Checkbox1">Checkbox1</label>
<input type="checkbox" value="checkbox2" name="search_filter[]">
<label for="Checkbox2">Checkbox2</label>
</form>
,并且在提交时重定向到此网址,并选中两个复选框
and it redirects to this URL upon submit with the 2 checkboxes checked
results?search_query = dreams& search_filter [] = checkbox1& search_filter [] = checkbox2
它的工作原理像这样(内部codeigniter我得到的数据与 $ this-> input-> get('search_filter')
),但我的问题是:I我在窗体中做错了,或者这是它应该如何工作?
我的意思是:& search_filter [] = checkbox1& search_filter [] = checkbox2
。应该不是这样的:& search_filter [] = checkbox1,checkbox2
?
It works like this (inside codeigniter I get the data with $this->input->get('search_filter')
), but my question is: I am doing something wrong inside the form, or this is how it's supposed to work?
And I mean about: &search_filter[]=checkbox1&search_filter[]=checkbox2
. Shouldn't it be something like: &search_filter[]=checkbox1,checkbox2
? And if not, how can I make it work like that?
推荐答案
如果你想要它的逗号格式,你可以做
If you want it in the comma format you can do the following:
$filters = (array) $this->input->get('search_filter');
$filters = implode(',',$filters);
如果要更改表单提交的格式,假设jquery for js:
If you want to alter the format in which the form is submitted, assuming jquery for js:
$('#search_form').submit(function() {
var $hidden = $('<input type="hidden" name="search_filter" />').appendTo($(this)),
$filters = $('input[name^=search_filter]'),
value = '';
//loop through the filters check if there checked and add them to the value
$hidden.val(value);
$filters.remove();
});
当然,如果用户没有启用js,它将原生地提交
Of course if the user doesn't have js enabled it will submit natively
这篇关于HTML复选框表单和HTTP URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!