Skip to content
Advertisement

django redirect to form view and autofill with previously entered values

I have following scenario.

  1. User fills out a form
  2. If the user clicks the “continue” button and the form is valid the user will be redirected to a summary view
  3. In the summary view the user checks the input again. He can either continue or go back.
  4. If he continues the data will be saved in the database, if he goes back he can edit the form.

Since in step 4 the user is at the view summary I have to redirect him to the home view. I don´t want the user to fill out the entire form again, the previously entered data should be autofilled if he goes back.

Something special: I am using django-tagify2 for one input in the form to get tags rather then text. If the user goes back the tags should be rendered correctly in the tagify specific form.

So here are my files:

home.html

JavaScript

summary.html

JavaScript

home view

JavaScript

summary view

JavaScript

So what is the best way to do this? Can I use the session variables to set the fields in the form?

I don´t want to change the logic in the app. I want a home/summary/success view/template where I can loop as long is I want between home and summary until the user is happy with his entered form data

Advertisement

Answer

I played around with the session values and views and finally got a way to redirect to other views with prefilled form fields based on session values.

JavaScript

Template

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement