如何发送同名的多个输入字段值? [英] How to send multiple input field values with same name?

查看:93
本文介绍了如何发送同名的多个输入字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有m2m字段,可以说它有关系,所以我想允许用户发送尽可能多的关系。我用相同名称的javascript添加新的输入到HTML,像这样

 < input type ='text'name ='relations 'value ='a'/> 
< input type ='text'name ='relationships'value ='b'/>在clean_data中

我只接收第二个输入('b')的值。如何收到这两个?

解决方案

我不知道如何使用Forms,但如果你想抓住值以原始方式,我将如何做:

  relations = request.POST.getlist('relations')


I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so

<input type='text' name='relations' value='a' />
<input type='text' name='relations' value='b' />

in cleaned_data i receive only value of second input ('b'). How to receive both?

解决方案

I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:

relations = request.POST.getlist('relations')

这篇关于如何发送同名的多个输入字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆