捕获 Rails 3 多选输入参数
我有一个多选表单控件(图 1)。当我选择超过 1 个值时,Firefox 会发送这两个值(图 2)。但只有最后一个值作为输入值发送到我的控制器(图 3)。如何将所有这些值传递到我的控制器?
<form action="html_items/search" method="post" >
<!-- Criteria -->
<div style="float:none;">
<label>Content Provider </label>
<select multiple id="content_provider" name="content_provider">
<option value="FLR">Flare</option>
<option value="SLDT">Slashdot</option>
</select>
</div>
<input type="submit" value="Search" />
</form>
如图。 1
参数application/x-www-form-urlencoded
content_provider FLR
content_provider SLDT
如图。 2
PARAMs[{"content_provider"=>"SLDT", "controller"=>"html_items", "action"=>"search"}]
...
如图。 3
谢谢
蒂姆
I have a multiselect form control (fig. 1). When I select more than 1 value, Firefox sends both values (fig. 2). But only the last value gets sent as a input value to my controller (fig. 3). How do I get all those values passed on to my controller?
<form action="html_items/search" method="post" >
<!-- Criteria -->
<div style="float:none;">
<label>Content Provider </label>
<select multiple id="content_provider" name="content_provider">
<option value="FLR">Flare</option>
<option value="SLDT">Slashdot</option>
</select>
</div>
<input type="submit" value="Search" />
</form>
fig. 1
Parametersapplication/x-www-form-urlencoded
content_provider FLR
content_provider SLDT
fig. 2
PARAMs[{"content_provider"=>"SLDT", "controller"=>"html_items", "action"=>"search"}]
...
fig. 3
Thanks
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一件事是,如果您想创建所选元素的数组,则需要将您的
;
接下来...如果未选择任何内容,则不会显示任何内容。这是有道理的,但它让我有点困惑。我正在做ajax,其中左侧选择是搜索结果,右侧是完成的列表。
我刚刚添加了一个
.click(function(){});
到我的提交按钮,将左侧的每个项目设置为使用 jQuery 选择,并且这些项目以数组的形式显示在参数中。在下面的示例中,您应该看到第一个项目出现。The first thing is that if you want to create an array of the elements that are selected you need to name your
<select>
something like<select name='foo[]'>
Next... If nothing is selected nothing will show up. This makes sense, but it stumped me for a bit. I was doing ajax where the left select was search results and the right was the completed list.
I just added a
.click(function(){});
to my submit button to set every item on the left to selected with jQuery and the items showed up in the parameters as an array. In the below example you should see the first item show up.