Hello,
Recently I’ve been trying to make 2 forms (call them form1 and form2). So basically, when form1 is submitted, I want to be redirected to form2. The problem is that it takes a ‘POST’ request to validate both forms. What happends is that form1 is validated via a ‘POST’ request then the view for form2 is called also with a ‘POST’ request. How would you go about changing that to a ‘GET’ request? Or do you have a better idea?
Thanks for reading regardless of the answer and have a great day!
Jude
Technically, a form does not redirect to another form. A form is just part of a page. A page redirects you to another page. (Which could be the same page.) This distinction is important when understanding what’s going on - you should be thinking in terms of pages and views, not forms.
For one approach on this, take a look at the Django Form Wizard in the django-formtools package.
There are a couple other approaches available as well.
Instead of full page replacements, you could use AJAX to submit the data from form 1 and replace that div with form 2.
Or, you could put the two forms on the same page in different divs, then have a button that switches between them. That would allow you to submit all the data at once in a single post.
It’s not really a question of “better” or “worse”, there are always tradeoffs. It’s only a question that best fits what you’re ultimately trying to accomplish.
Thank you very much!