【问题标题】:How to handle multi criterias search in PHP如何在 PHP 中处理多条件搜索
【发布时间】:2018-04-01 11:42:05
【问题描述】:

我在我的网站上进行过滤时遇到了一点问题。 我有一个存在于所有页面中的表单,用户可以使用此表单按名称和类别搜索产品。代码如下所示:

<form method = "GET" action = "{!! route('search_product') !!}">
   <input type = "text" name = "searchText"/>
   <select name="category">
    ...
   </select>
</form>

当用户提交表单时,我会得到一个这样的 url:search_result.php?searchText=test&category=1

一切正常。问题是在 search_result 页面上我有另一个表单,其目的是使用户能够按价格缩小产品列表。

<form method = "GET" action="{!! route('search_product') !!}">
    <input name = "min" type = "text"/>
    <input name = "max" type ="text" />
</form>

通过这样做,在提交表单时删除了先例参数(searchText 和类别)。那么如何保留它们。

PS:抱歉英语不好。

【问题讨论】:

    标签: php elasticsearch laravel-5 get


    【解决方案1】:

    在新表单中使用 2 个隐藏输入,填充 searchTextcategory 的值,这样您将在第二次提交后获得这些值。

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

    【讨论】:

    • 我自己想通了,不过感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多