Let's say I have the 3 different forms defined in my view:
# views.py
form_one = FormOne()
form_two = FormTwo()
form_three = FormThree()
In my template:
<form action="" method="post" id="form-one">
{{ form_one.as_table }}
<input type="submit" value="Submit Form One" name="form-one" />
</form>
<form action="" method="post" id="form-two">
{{ form_two.as_table }}
<input type="submit" value="Submit Form Two" name="form-two" />
</form>
<form action="" method="post" id="form-three">
{{ form_three.as_table }}
<input type="submit" value="Submit Form Three" name="form-three" />
</form>
Assuming each form has their own unique field names, how do I handle all 3 forms from one view? I was thinking of the following method but I'm not sure if it's the best way to tackle this issue:
# views.py
if request.method == 'POST':
request_post = request.POST
if 'form-one' in request_post:
form_one = FormOne(request.POST)
elif 'form-two' in request_post:
form_two = FormTwo(request.POST)
else:
form_three = FormThree(request.POST)
else:
form_one = FormOne()
form_two = FormTwo()
form_three = FormThree()
Any comments or suggestions?