gpt4 book ai didi

php - HTML 复选框表单和 HTTP URL

转载 作者:行者123 更新时间:2023-12-01 15:44:46 24 4
gpt4 key购买 nike

所以,我有这个 HTML 表单:

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

并在提交时重定向到此 URL,并选中 2 个复选框

results?search_query=dreams&search_filter[]=checkbox1&search_filter[]=checkbox2

它是这样工作的(在 codeigniter 中,我使用 $this->input->get('search_filter') 获取数据),但我的问题是:我在表单中做错了,或者这就是它应该如何工作?我的意思是:&search_filter[]=checkbox1&search_filter[]=checkbox2。它不应该是这样的: &search_filter[]=checkbox1,checkbox2 吗?如果没有,我怎样才能让它像那样工作?

最佳答案

如果您想要逗号格式,您可以执行以下操作:

$filters = (array) $this->input->get('search_filter');
$filters = implode(',',$filters);

如果你想改变提交表单的格式,假设 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,它将本地提交

关于php - HTML 复选框表单和 HTTP URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8911313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com