views:

229

answers:

2

What are some RESTful ways to transition between pages of a multi-page form in Django?

My current method:

  1. form POSTs to same page
  2. form view validates and stores POST data in session
  3. form view redirects to the next form page upon successful validation.
  4. next form checks if previous data exists. if not, redirects to first form.

Are redirects between form pages bad? Should forms POST to the next form page? If so, where should form validation happen?

A: 

Django has form wizards which handle this machinery (in case you were unaware).

http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/

Koobz
Thanks! I'm aware, but wanted to know my other options.I use formsets and need access to previous data at each form, which complicates using form wizard. I do see there is a patch for using form wizard with formsets ( http://code.djangoproject.com/ticket/11112 ).
Ian Cohen
+1  A: 

What you're doing sounds like an implementation of the PRG model for handling multi step forms.

You probably want to POST to the current step, and then redirect to the next step only if the form validates. There is no problem with redirecting between steps; in fact, as you probably discovered, it allows you to support the browser back button in your forms.

tobias.mcnulty