# Using multi step form

**URL:** <https://forum.djangoproject.com/t/using-multi-step-form/8634>\
**Category:** Forms & APIs\
**Created:** [July 5, 2021, 10:39pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634 "2021-07-05T22:39:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tragicomic](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tragicomic/32/2285_2.png) [@tragicomic](https://forum.djangoproject.com/u/tragicomic)\
**Post date:** [July 5, 2021, 10:39pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/1 "2021-07-05T22:39:34Z")

</div>

I have a multi step form design. I am trying send form data using my modelform.  
After I render the fields manually, I try to submit data but nothing submitted the db.

I suppose that the problem is because it’s a multi-step form.  
I tried to transfer the data between steps using ‘session’ but I don’t know exactly what the structure should be.

This is my form,

```auto
class NameForm(forms.ModelForm):
	class Meta:
    	model = NameModel
    	fields = ('field_1', 'field_2', 'field_3', 'field_4', 'field_5', 'field_6' )
      
    	widgets = { ....}

```

This is from the template,  
There are two fieldsets in the form element.

```auto
        <form action="" method="post" class="contact-form">
          {% csrf_token %}
          <h6>Form Heading</h6>
          <div class="contact-form__step-control">
            <span class="active"></span>
            <span></span>
          </div>
          
          <fieldset class="contact-form__block">
            <div class="form-item form-item--border">
              {{ form.field_1 }}
            </div>
            <div class="form-item form-item--border">
              {{ form.field_2 }}
            </div>
            <div class="select-item">
              <select name="abcd" id="id_abcd" required>
                {% for abcd in form.field_3 %}
                  {{ abcd }}
                {% endfor %}
              </select>
            </div>
          </fieldset>
          
          <fieldset class="consultant-contact-form__block">
            <div class="form-item form-item--border">
              <div class="select-item">
                <select name="qwerty" id="id_qwerty" required>
                  {% for qwerty in form.field_4 %}
                    {{ qwerty }}
                  {% endfor %}
                </select>
              </div>
              <div class="form-item form-item--textarea form-item--border">
                {{ form.field_5 }}
              </div>
              <div class="form-item form-item--textarea form-item--border">
                {{ form.field_6 }}
              </div>
          </fieldset>
          
          <div class="contact-form__navigation">
            <button type="button"
              class="primary-btn primary-btn--medium next">Next</button>
            <button id="btnsubmit" type="submit" class="primary-btn primary-btn">Submit</button>
          </div>
        </form>

```

This is my view, before I try to use sessions.

```auto
def viewname(request):
	if request.method == 'GET':
		form = NameForm()
	else:
    #something about recaptcha
    #...
    if result['success']:
		form = NameForm(request.POST)
		if form.is_valid():
       		# process the data in form.cleaned_data
       		#...
            #something about sending mail
            #...
            
            return HttpResponseRedirect('/thanks/')
    else:
		form = NameForm()
    return render(request, 'name.html', {'form': form})

```

I have in mind to use these, but I do not know how to apply them according to my own view and structure.

```auto
#...
initial = { 'field_name': request.session.get('field_name', None), 
...}

#...
request.session['field_name'] = form.cleaned_data['field_name']

#...             
field_name = request.session['field_name']

```

What kind of structure do I need to set up to be able to successfully send data in this kind of multi step form ?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 5, 2021, 10:44pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/2 "2021-07-05T22:44:17Z")

</div>

Take a look at the Form Wizard in [django-formtools](https://django-formtools.readthedocs.io/en/latest/wizard.html). Even if it’s not exactly what you’re looking for, it might give you some ideas on how to handle this.

---

<div class="post-metadata">

**Author:** ![tragicomic](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/tragicomic/32/2285_2.png) [@tragicomic](https://forum.djangoproject.com/u/tragicomic)\
**Post date:** [July 5, 2021, 11:22pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/3 "2021-07-05T23:22:41Z")

</div>

Thank you for your interest.

I tried to use it before, but I couldn’t use it properly for my needs.  
I had a hard time configuring it as it has a standard structure.

It is difficult to use WizardView and I could not manually render the form fields according to my form design.

Do you think it is necessary to use the form wizard to apply my form structure you see?  
Isn’t there a simple solution using sessions as I think?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 5, 2021, 11:27pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/4 "2021-07-05T23:27:16Z")

</div>

There’s no requirement to use that library directly, you can read the source for it to see how it handles the forms, and apply the principles in your own code.

---

<div class="post-metadata">

**Author:** ![richysleeks](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/richysleeks/32/7215_2.png) [@richysleeks](https://forum.djangoproject.com/u/richysleeks)\
**Post date:** [January 27, 2022, 1:58am UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/5 "2022-01-27T01:58:50Z")

</div>

I know that is coming late but it might help someone with similar problem.

I remember running into same problem and I solved it by changing the submit button type to

---

<div class="post-metadata">

**Author:** ![PopyTheSailor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/popythesailor/32/18439_2.png) [@PopyTheSailor](https://forum.djangoproject.com/u/PopyTheSailor)\
**Post date:** [January 16, 2024, 9:58am UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/6 "2024-01-16T09:58:10Z")

</div>

Is it possible to use Formtools directly within Django admin panel? I am trying to add a wizard type view within my Django admin

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 16, 2024, 12:58pm UTC](https://forum.djangoproject.com/t/using-multi-step-form/8634/7 "2024-01-16T12:58:37Z")

</div>

Probably not. If that’s something you’re thinking of doing, you should be creating your own views for it.

Quoting directly from the [Django admin docs](https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#module-django.contrib.admin)

> If you need to provide a more process-centric interface that abstracts away the implementation details of database tables and fields, then it’s probably time to write your own views.
