简体   繁体   English

html 带有 get 方法的表单正在为同一个输入数组创建多个查询参数

[英]html form with get method is creating multiple query parameters for the same input array

Let's say I have this simple form:假设我有这个简单的形式:

<form action="/search/" method="get" role="search">
    <input name="cars[]" value="saab">
    <input name="cars[]" value="honda">
    <input name="cars[]" value="toyota">
    <input type="submit" value="submit">
</form>

After clicking submit I am being redirected to the search results page and the URL looks like this: https://example.com/search/?cars=saab%5B%5D&cars=honda%5B%5D&cars=toyota单击提交后,我被重定向到搜索结果页面,URL 如下所示: https://example.com/search/?cars=saab%5B%5D&cars=honda%5B%5D&cars=toyota

Questions:问题:

  1. Why is this piece of code %5B%5D added to the url and can I get rid of it?为什么这段代码%5B%5D添加到 url 中,我可以去掉它吗?
  2. Why is cars appearing multiple times?为什么汽车会出现多次? Can I simple have ?cars=saab,honda,toyota ?我可以简单地拥有?cars=saab,honda,toyota吗?

Thanks谢谢

Each input must have a unique name, just change names.每个输入必须有一个唯一的名称,只需更改名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM