Skip to content
Advertisement

Django form keeps information after submission

I have a Django form and I am trying different options to do 2 things when the form is submitted:

  1. Redirect the form back without any information
  2. Trigger a Modal after a Django Form is submitted.

I have followed this answer but it did not work the form was successfully submitted but the modal did not appear.

I have added the context of successful_submit in the views so that it can be triggered after submitting the form

Here is part of the HTML Template:

JavaScript

here is the javascript part to show it when it is successfully submitted

JavaScript

here is the views.py

JavaScript

Advertisement

Answer

On triggering the modal:

At the last line of add__plan(request), you are passing successful_submit as True which should make the modal load when you first load the page (before form submission) i.e. the modal should be shown without submitting the form.

successful_submit should be False initially.

JavaScript

Let’s say that you have successful_submit=True as per the code you have provided. Then, the modal should pop up when you load the page. If modal is not showing:

  • check browser console for any errors
  • check if JQuery and Bootstrap are loaded in the correct order
Advertisement