BMoe872
BMoe872

Reputation: 140

How to have single form on multiple pages

I am looking for ways to best handle a single form on multiple pages. Like how a newsletter signup might be on a home page, an about page, and several blog pages.

I've handled this exact scenario in these 2 ways.

  1. Write an API (using DRF) that takes a POST request, and then point the normal HTML form at that API. This works, and is very flexible, but feels like overkill.

  2. Pass the form object into the context of each view I want the form to be on, and then include that into the template with includes form_snippet with form=form

The first approach is more flexible with wagtail, wherein all that needs to happen on the admin side is an inclusion of the newsletter as a snippet, where the admin user is able to choose if they want the newsletter on the page or not.

While both approaches work just fine, neither of them "feels" right, as I would think there is a simple way to do this without creating a big API, or passing around the form object to every single view.

Upvotes: 0

Views: 555

Answers (2)

Wim Feijen
Wim Feijen

Reputation: 874

three years later on you probably found an answer.

For documentation purposes and Google searchers, Wagtail offers an explanation on how to make a multiple step form here: https://docs.wagtail.org/en/v3.0.1/reference/contrib/forms/customisation.html#multi-step-form

Upvotes: 1

onezero
onezero

Reputation: 31

I did this with a contact formular. I handled it with a new app for my contact formular. In this contactApp is the templates/contactForm.html. To include this contactForm where I want I use {% include 'contact/contactForm.html' %} so it loads the contactForm.html from my app called contact.

Upvotes: 0

Related Questions