views:

52

answers:

1

The form looks very simple:

class MyForm(forms.Form):
    ids = forms.MultipleChoiceField(widget=forms.MultipleHiddenInput())


def view(request):
  ...
  form = MyForm(initial={'ids': [o.id for o in queryset]})

Which gives me the HTML (which looks good enough):

<form method="post" action="/foo/bar/">
<input type="hidden" name="ids" value="7720889" id="id_ids_0">
<input type="hidden" name="ids" value="7717962" id="id_ids_1">
<input type="hidden" name="ids" value="7717807" id="id_ids_2">
<input type="hidden" name="ids" value="7713584" id="id_ids_3">
<input type="hidden" name="ids" value="7712277" id="id_ids_4">
<input type="hidden" name="ids" value="7707475" id="id_ids_5">
<input type="hidden" name="ids" value="7707257" id="id_ids_6">
<input type="hidden" name="ids" value="7705271" id="id_ids_7">
<input type="hidden" name="ids" value="7704338" id="id_ids_8">
<input type="hidden" name="ids" value="7704137" id="id_ids_9">
<input type="hidden" name="ids" value="7695444" id="id_ids_10">
<input type="hidden" name="ids" value="7695242" id="id_ids_11">
<input type="hidden" name="ids" value="7690683" id="id_ids_12">
<input type="hidden" name="ids" value="7690431" id="id_ids_13">
<input type="hidden" name="ids" value="7689035" id="id_ids_14">
<input type="hidden" name="ids" value="7681230" id="id_ids_15">
<input type="hidden" name="ids" value="7679189" id="id_ids_16">
<input type="hidden" name="ids" value="7675315" id="id_ids_17">
<input type="hidden" name="ids" value="7667291" id="id_ids_18">
<input type="hidden" name="ids" value="7661162" id="id_ids_19">
<button type="submit">Test</button>
</form>

But, in the POST that comes in, I'm only getting one value:

<QueryDict: {u'ids': [u'7661162']}>

What gives? What am I doing wrong?

+1  A: 

I believe you want request.POST.getlist('ids') which should return a list of all the values set for ids.

Josh Ourisman