merge 2 input values in url

笑着哭i 提交于 2019-12-09 03:51:28

问题


I have form like this:

<form action="" method="get">
Color: <input type="text" name="color"><br>
Car: <input type="text" name="car"><br>
<input type="submit">
</form>

When i type color "red" and car "bmw" i get url like this

http://mywebsite/?color=red&car=bmw

how can i get car array into color on submit so that it would be like this

http://mywebsite/?color=red+bmw


回答1:


I don't really know of a way to modify the HTML form to produce that query string from two separate inputs. But in the PHP script that handles the form submission, the URL you're trying to get is basically the equivalent of this:

$_GET['color'] = implode(' ', $_GET);
unset($_GET['car']);

This will change $_GET to

array (size=1)
  'color' => string 'red bmw' (length=7)

as if you had submitted to

http://mywebsite/?color=red+bmw


来源:https://stackoverflow.com/questions/46919241/merge-2-input-values-in-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!