更改具有多个选择的表单上的 $_GET 字符串
我有一个包含多个选择的表单,提交表单时得到的 url 如下所示:
tld.com/?var1=opt1$var1=opt2&var1=opt3&var2=opt1&var2=opt2
url我想获得的是:
tld.com/?var1=opt+opt2+opt3&var2=opt1+opt2
我不想使用$_POST 方法,选项存储在数组中,因为我希望 url 对于任何自定义搜索都是唯一的。
表格看起来像这样:
<form action="" method="get">
<select name="var1" multiple="multiple">
<option value="var1">one</option>
<option value="var2">two</option>
<option value="var3">three</option>
<option value="var4">four</option>
<option value="var5">five</option>
</select>
<select name="var2" multiple="multiple">
<option value="var1">one</option>
<option value="var2">two</option>
<option value="var3">three</option>
<option value="var4">four</option>
<option value="var5">five</option>
</select>
<input type="submit" value="Send" />
</form>
I have a form with a couple of multiple selects and the url I get when submitting the form is something like this:
tld.com/?var1=opt1$var1=opt2&var1=opt3&var2=opt1&var2=opt2
The url I woul like to obtain is:
tld.com/?var1=opt+opt2+opt3&var2=opt1+opt2
I do not want to use the $_POST method with the options stored in an array because I want the url to be unique for any custom search.
The form looks something like this:
<form action="" method="get">
<select name="var1" multiple="multiple">
<option value="var1">one</option>
<option value="var2">two</option>
<option value="var3">three</option>
<option value="var4">four</option>
<option value="var5">five</option>
</select>
<select name="var2" multiple="multiple">
<option value="var1">one</option>
<option value="var2">two</option>
<option value="var3">three</option>
<option value="var4">four</option>
<option value="var5">five</option>
</select>
<input type="submit" value="Send" />
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在客户端构建 2 个数组并通过表单发布它,但在服务器端您将获得 2 个数组并从中配对。您真的需要它吗?
它将类似于
You will get URL
?name1+name2+name3=value1+value2+value3
UPD: just use
[]
in name 属性:您将得到
/?var1=param1+param2
You can try to build 2 arrays on client side and post it through the form, but on server side You will get 2 arrays and make pairs from them anyway. Do You really need it?
It'll be something like
You will get URL
?name1+name2+name3=value1+value2+value3
UPD: just use
[]
in name attribute:You'll get
/?var1=param1+param2