Opened 10 years ago
Closed 10 years ago
#22677 closed Bug (duplicate)
forms.Form silently won't bind to POST data (under certain combinations of key and label)
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Generic views | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
In this example:
class TestFormX(forms.Form): test_one = forms.CharField(required=True) def __init__(self, *args, **kwargs): super(TestFormX, self).__init__(*args, **kwargs) self.fields['test_two'] = forms.IntegerField(required=False) for key in (3,4): self.fields[key] = forms.IntegerField(required=False, label='must have a label') def sandbox2(request): if request.method == 'POST': form = TestFormX(request.POST) if form.is_valid(): print 'Form is valid' else: print form.errors else: form = TestFormX() return render(request, 'xxx_sandbox2.html', {'form' : form}, status=200)
Form fields one and two act normally. Fields 3 and 4 appear to work, but
don't bind data from the request.POST. Thus, any input by the user is lost.
This was found on a dynamically built from.Form, where the database primary key was used as the field name.
Note:
See TracTickets
for help on using tickets.