django submit multiple forms code example
Example 1: multiple form in one class djanog
class MultipleFormsDemoView(MultiFormsView):
template_name = "pages/cbv_multiple_forms.html"
form_classes = {'contact': ContactForm,
'subscription': SubscriptionForm,
}
success_urls = {
'contact': reverse_lazy('contact-form-redirect'),
'subscription': reverse_lazy('submission-form-redirect'),
}
def contact_form_valid(self, form):
'contact form processing goes in here'
def subscription_form_valid(self, form):
'subscription form processing goes in here'
Example 2: handling multiple forms flask
<form>
<input type="hidden" name="form-name" value="form1">
</form>
<form>
<input type="hidden" name="form-name" value="form2">
</form>
def some_view():
form1 = SomeForm()
form2 = AnotherForm()
if request.method == 'POST':
form_name = request.form['form-name']
if form_name == 'form1':
form1.validate()
...