从第二种形式传递第二个参数?

时间:2017-03-18 15:50:52

标签: php laravel

我正在使用laravel 5.4,我的问题是如何从不同的表单中传递第二个参数。

我知道当我有多个相同形式的输入时,我可以传递多个参数

<form action="" method="get">
   <input type="text" name="country" placeholder="country">
   <input type="text" name="town" placeholder="town">
</form>

如果我在这里搜索,我会得到类似的东西 website.com/?country=croatia&town=zagreb

但是如何从两种形式获得相同的结果

<form action="" method="get">
   <input type="text" name="country" placeholder="country">
</form>

<form action="" method="get">
   <input type="text" name="town" placeholder="town">
</form>

我需要能够搜索一个表单,然后是第二个表单,如果我想要的话 让我说我先搜索一个国家,然后我

website.com/?country=croatia

现在我想搜索一个城镇,我得到了

website.com/?country=croatia&town=zagreb

它应该反过来了!(如果我首先搜索一个城镇,然后搜索一个国家。我知道这是一个不好的例子)

1 个答案:

答案 0 :(得分:3)

你要做的事情有点复杂。但是有一些解决方法。

您的第一份表格

<form action="" method="get">
    <input type="text" name="country" placeholder="country">
</form>

你的第二张表格

<form action="" method="get">
    <input type="hidden" name="country" value="{{ request('country') }}">
    <input type="text" name="town" placeholder="town">
</form>

当您提交第二个表单时,它实际上会通过从URL中获取值来重新创建URL。在一天结束时,您将第二个表单“添加”到URL的参数。