tags:

views:

49

answers:

1

In my Django webapp, I have a user submit data to Form1.html. The data is passed onto Form2.html where they submit more data. After they submit Form2 they are taken to Done.html.

Form1 >> Form2 >> Done

The problem is I need the data from Form1 in From2 and in the Done view. Getting the data from Form1 to the Form2 view is no problem, just grab the values from request.POST['value']. In Form2 view, how do I pass on the Form1-data to the Done view? I thought that I could just modify the POST object in Form2 like below and pass the request object on:

def form2(request):
    form1string = request.POST['inputbox1']

    request.POST = request.POST.copy() # make the POST QueryDict mutable
    request.POST.setdefault('data1', form1string)

    t = loader.get_template('done.html')
    c = RequestContext( request, {  # pass on old request so new POST data is passed on
        'blah': some_var,
    })
    c.update(csrf(request)) # add the csrf_token to the Context dictionary
    return HttpResponse(t.render(c))

I'm kind of hesitant to use django.sessions as not everyone has cookies enabled.

Thanks in advance for the help!

+1  A: 

I would start reading here: http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/

Regarding being hesitant about sessions :

It maintains state in hashed HTML fields

dysmsyd
Wow, haven't heard about this contrib app, seems useful. Thanks!
Dmitry Gladkov