working with multiple html forms django

Solutions on MaxInterview for working with multiple html forms django by the best coders in the world

showing results for - "working with multiple html forms django"
Luis
19 Jan 2020
1if request.method == 'POST':
2    form1 = Form1( request.POST,prefix="form1")
3    form2 = Form2( request.POST,prefix="form2")
4    
5    if form1.is_valid():
6       # save them    
7       
8       # context['form1_message'] = 'Form1 saved'
9    else: 
10       #save them into context
11       context['form1']= form1
12    
13    if form2.is_valid():
14       # save them    
15       # context['form2_message'] = 'Form2 saved'
16    else: 
17       #save them into context
18       context['form2']= form2
19
20    if form1.is_valid() and  form2.is_valid(): 
21       #that's mean both form is valid and saved successfully 
22       return redirect('page')
23    else:
24        return render('/page', context)
25
26
27else:
28    form1 = Form1(prefix="form1")
29    form2 = Form2(prefix="form2")
30
Sofia
05 May 2017
1# views.py
2def _get_form(request, formcls, prefix):
3    data = request.POST if prefix in request.POST else None
4    return formcls(data, prefix=prefix)
5
6class MyView(TemplateView):
7    template_name = 'mytemplate.html'
8
9    def get(self, request, *args, **kwargs):
10        return self.render_to_response({'aform': AForm(prefix='aform_pre'), 'bform': BForm(prefix='bform_pre')})
11
12    def post(self, request, *args, **kwargs):
13        aform = _get_form(request, AForm, 'aform_pre')
14        bform = _get_form(request, BForm, 'bform_pre')
15        if aform.is_bound and aform.is_valid():
16            # Process aform and render response
17        elif bform.is_bound and bform.is_valid():
18            # Process bform and render response
19        return self.render_to_response({'aform': aform, 'bform': bform})
20
21# mytemplate.html
22<form action="" method="post">
23    {% csrf_token %}
24    {{ aform.as_p }}
25    <input type="submit" name="{{aform.prefix}}" value="Submit" />
26    {{ bform.as_p }}
27    <input type="submit" name="{{bform.prefix}}" value="Submit" />
28</form>
29
queries leading to this page
multiple form djangodjango two total formsmultistep forms djangodjango multiple formsetdjango view multiple formsmultiple forms djangodjango forms multiwidgethow to use two submit buttons in one form in djangohow to show multiple forms for multiple models djangotwo forms one page djangodjango multiple forms one submitdjango use multiple forms in viewhow to create single form for multiple pages in djangodjango total forms twomultiple form handeling djangodjango multiple forms on one pagedjango forms field field multiplemultiple forms on one page djangoformset with multiple forms djangohow can i add multiple forms in one page djangotwo forms in one template django2 forms in one html page djangodjango multi form examplehow to use multiple forms in django single viewsadding multiple forms to a django pagedjango handle two form in one pagedjango multiple formshow to connect multiple forms in a single page to a database in djangodjango form two submit buttonsmulti valued django formssubmit multiple forms at once in djangodjango form helper add submit to specific form when multiple forms on same pagedjango multiple forms one viewbutton submit multiple fields in djangohow to add multiple in django formmultiple data send in django formshow to have two forms in one view in djangodjango forms can i include two forms in one viewtwo forms in one django viewsubmit two form with same button djangohow to handle two forms in one page djangoone submit button for multiple forms djangouse multiple form djangouse one submit button for 2 forms djangodjango two forms one submitdjango use two formuse two django form on the same pagemultiple forms in single view djangomultiple form in djangomultiple forms view py djangodjango multiple forms in one class based viewmultiple forms in djangp templatemultiple forms in one page djangoproper way to handle multiple forms in one page in djangodjango multiple forms one pagedjango multiple forms on a pagehow to get two form value in one submit in djangotwo forms on one page djangoform multichoicefied in django formsmulti page forms djangouse multiple form django cbvdjango multiple forms in one templateuse 2 forms in djangomultiple form with django templateviewproper way to handle multiple forms on one page in djangodjango multiple form in one viewhow to submit two different forms to two different models djangohow to render two different forms in the same view in django but submit differentlyhow to use two different django form at the same templatetwo forms in one page djangodjango with 2 submit on form templatedjango multiple forms for one modelmultiple forms on one forms in djangohow to have multiple forms in aview in djangodjango multi formsforms with multitple model djangdjango multiple formsetsmultiple form data djangoseveral submit buttons in form django templatedjango form two buttons in one form only one should workmulti form in djangodjango formset add multiple of the same formuse two forms in one view django formsadd multiple forms django inlineformsethow to deal with several forms on one page in djangohandling multiple forms in djangodjango formview multiple formsdjango two forms on one pagedjango form multiple fieldsform 3d two forms djangodjango two form in one htmlmultiple forms in djangotwo formsets one form djangohaving multiple form in one django templateproper way to handle multiple html forms created in one page in djangosubmit two forms with one view djangohow to render two different forms in the same iew in djangomultiple form in one form django createdjango two form in one templatehow to identify forms in case of multiple forms in djangousing one form in two django templateshow to add multiple forms in djangosubmit multiple forms djangodjango multiple forms in viewhow do i handle multipple forms on teh same page djangohow to understand which form is submitted if i have multiple forms in a page djangosubmitting multiple forms as one djangoworking with multiple html forms djangodjango form with multiple models 22forms 22 django several fields in one linemultiplepage forms djangohow to get 2 forms in django in one html pagework with two forms in one view djangoformset from two form djangoprocess multiple forms in the samge page djangotwo forms in post djangoworking with multiple html forms django