合并 url 中的 2 个输入值 [英] merge 2 input values in url
问题描述
我有这样的表格:
当我输入颜色red"和汽车bmw"时,我得到这样的网址
http://mywebsite/?color=red&car=bmw >
我怎样才能在提交时让汽车数组变成颜色,这样它会像这样
http://mywebsite/?color=red+bmw
我真的不知道有什么方法可以修改 HTML 表单以从两个单独的输入生成查询字符串.但是在处理表单提交的 PHP 脚本中,你试图获取的 URL 基本上是这样的:
$_GET['color'] = implode(' ', $_GET);未设置($_GET['汽车']);
这会将 $_GET
更改为
数组(大小=1)'颜色' =>字符串红色宝马"(长度=7)
就好像你已经提交
http://mywebsite/?color=red+bmw
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
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
这篇关于合并 url 中的 2 个输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!