如何在PHP中处理多个标准搜索
问题描述:
我在我的网站上执行过滤器时遇到了一些问题。 我有一个表单存在于所有页面中,这个表单用户可以按名称和类别搜索产品。代码如下所示:如何在PHP中处理多个标准搜索
<form method = "GET" action = "{!! route('search_product') !!}">
<input type = "text" name = "searchText"/>
<select name="category">
...
</select>
</form>
当用户提交形成我会得到一个URL是这样的:search_result.php SEARCHTEXT =测试&类别= 1
它的做工精细。问题是,在search_result页面上,我有另一种形式,其目的是使用户能够按价格缩小产品列表。
<form method = "GET" action="{!! route('search_product') !!}">
<input name = "min" type = "text"/>
<input name = "max" type ="text" />
</form>
通过这样做提交表单时删除了先前的参数(searchText和category)。所以如何保持它们。 PS:对不起,英语不好。
答
使用2倍隐藏的投入,充满了SEARCHTEXT和类别的值,在新的形式和这种方式后,你将有值第二提交。
<form method = "GET" action="{!! route('search_product') !!}">
<input name="searchText" type="hidden" value="<?=$searchtext;?>" />
<input name="category" type="hidden" value="<?=$category;?>" />
<input name = "min" type = "text"/>
<input name = "max" type ="text" />
</form>
我想出了自己,不过谢谢你的回答。 – kulturman