Skip to content
Advertisement

How to connect 2 forms in HTML and Django?

I am creating a web page and i’m wondering if i could make sure that the data on the left is filled before pressing the blue button. On the left you can see a form to pay by entering your address, city etc. but on the right you can see another form with stripe implemented to pay with credit card. I don’t know how to get the data from the left and save it in the database so I can create a receipt after successful payment. Here is the code down below.

JavaScript

AND HERE IS THE SCREENSHOT OF THAT ‘CONTAINER-2’ enter image description here

Advertisement

Answer

Firstly make sure all your inputs are under one form and one view.

Use required=True in your Django form in order to make sure every input is entered.

If you are using Django forms, for example

JavaScript

In your view use the form is_valid method

JavaScript

Use the form to save your data. If using Django form is not an option, you have to use javascript to disable the button until all inputs are not filled up

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