Hi group.  Please look at this view:

# this form runs the search mechanism
def DoSearchForm (request):
    if request.method =='POST':
        form=SearchForm (request.POST)
        if form.is_valid():
            try:
                myuid=request.user.id * 1
            except:
                myuid=0
            #form submitted passes validation so submit to database as
a valid search term record
            mydata = SearchAttempt (
                Terms = CleanMe(request.POST.get('Terms','')),
                suid = myuid
                )
            mydata.save()   #save to sarch_attempt table
            # save items to session variables
            request.session["Terms"]=request.POST.get('Terms','')
            request.session["Iforand"]=request.POST.get('Iforand','')
            request.session["Programelement"]=request.POST.get
('Programelement','')
            request.session["Disaster"]=request.POST.get
('Disaster','')
            request.session["Submissionmethod"]=request.POST.get
('Submissionmethod','')

            return HttpResponseRedirect('/search/results/')
        else:
            return render_to_response('submit-search.html', {'form':
form}, context_instance=RequestContext(request))
    else:    # load form for first time
        if 'Terms' in request.session:
            form = SearchForm(initial={'Terms':request.session
['Terms'],'Iforand':request.session
['Iforand'],'Programelement':request.session
['Programelement'],'Disaster':request.session
['Disaster'],'Submissionmethod':request.session['Submissionmethod']})
        else:
            form = SearchForm(initial={'Iforand':'exact'})
        return render_to_response('submit-search.html', {'form':
form}, context_instance=RequestContext(request))


This view is working perfectly except for one thing.  If someone
completes the form, it saves the form options to a session and inserts
the term they searched for into the database.  If they close their
browser and come back to the search form, I want their previous
choices to populate the form again.  Terms and Iforand populate as
they should.  Programelement, Disaster, and Submissionmethod are all
multiplechoicefield textbox lists and none of the previously selected
options are selected.  Can you see what i'm doing wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to