0

I have a simple form for a user to enter in Name (CharField), Age(IntegerField), and Sex(ChoiceField). However the data that is taken from the Sex choice field is not showing up in my cleaned_data(). Using a debugger, I can clearly see that the data is being received in the correct format but as soon as I do form.cleaned_data() all sign of my choice field data is gone. Any help would be greatly appreciated. Here is the relative code:

  class InformationForm(forms.Form):
     Name = forms.CharField()
     Age = forms.IntegerField()
     Sex = forms.ChoiceField(SEX_CHOICES, required=True)

   def get_information(request, username):
       if request.method == 'GET':
           form = InformationForm()   
       else:
           form = RelativeForm(request.POST)
           if form.is_valid():
               relative_data = form.cleaned_data
ikottman
  • 1,996
  • 3
  • 21
  • 23
  • 2
    You're using a different form for handling the data. Can you post the code for `RelativeForm`? I'm guessing it doesn't the `Sex` field... – Zach Jun 08 '10 at 15:54
  • You are indeed correct. I am using multiple forms depending on the situation and I was using the default one (RelativeForm) which doesn't include the Sex field. Thank you for helping me find this dumb mistake... – ikottman Jun 09 '10 at 13:25

2 Answers2

0

This may be silly but did you properly format SEX_CHOICES above the class or in a global fields directory? ex.

SEX_CHOICES = (
    ('M', 'Male'),
    ('F', 'Female'),
    ('O', 'Other'),
)

Or maybe it's best to format Sex as a forms.radio widget, so you have radio buttons instead of a drop-down as i believe the choicefield defaults to (correct me if i'm wrong)

Elaina R
  • 133
  • 7
0

The form that I was using in POST did not include the Sex field so of course the data dissappeared.

ikottman
  • 1,996
  • 3
  • 21
  • 23