zhyr28
unread,Jan 17, 2012, 2:05:07 AM1/17/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi all, I want to develop a survey app that has ten radio selects.
After people submit the survey, the data will be processing and then
output the result. I met a problem when I was trying to process the
data from the form. Here is the code:
forms.py: contains the survey questions.
QUESTION_ONE= (('4','Black',), ('3', 'Red',), ('2', 'Green',), ('1',
'Purple',))
lass SurveyForm(forms.Form):
q1 = forms.ChoiceField(
widget=forms.RadioSelect, # radio select
label=u" 1. What's your prefered colour?",
choices = QUESTION_ONE # four choices
)
views.py
def take_survey(request):
if request.method=='POST':
form = SurveyForm(request.POST)
if form.is_valid():
p1 = form.cleaned_data['q1'] # get the result of input
p = p1[0] #get
the number
if p>2:
return HttpResponseRedirect('a.html') # if
user choose black or red, then redirect user to a.html
i cannot get the correct result, but I do not know which step is
wrong. Hope someone could help me. Thank you.