How can I tell in my django view, which of the 2 forms' fields were filled?
<p>I want to display both <code>form1</code> and <code>form2</code> on a web page. If <code>form2</code> is filled (<code>if success == True</code>), I want my view to not execute    <code>if form1.is_valid:</code></p>

<p>(which gives errors). How can I access the value of <code>success</code> in views.py?</p>

<p>forms.py</p>

<pre><code>class Form1(forms.Form):
    ....
    ....
    def clean(self):
        ....
        ....

class Form2(forms.Form):
    ....
    ....
    def clean(self):
        ....
        success = False
</code></pre>

<p>views.py</p>

<pre><code>def my_view(request, element_pk):
    ....
    ....
    if request.method == POST:
        form2 = Form2(request.POST)
        form1 = Form1(request.POST)

    if form2.is_valid():
        ....
    if form1.is_valid():
        ....

    else:
        form2 = Form2()
        form1 = Form1()
</code></pre>

<p>For your <code>&lt;input /&gt;</code> or <code>&lt;button&gt;&lt;/button&gt;</code> tag, use a <code>name</code> parameter for each form (i.e.):</p>

<pre><code>&lt;button type="submit" name="form_1"&gt;Go!&lt;/button&gt;
</code></pre>

<p>Then, in your view, do something like:</p>

<pre><code>if form2.is_valid() and 'form_2' in request.POST:
    . . .
if form1.is_valid() and 'form_1' in request.POST:
    . . .
</code></pre>

python django django-forms django-views