4👍
In order to persist the values from multiple forms from one POST, you’ll need to have all of the fields in one form (without using JavaScript).
In your view action, you would need to validate each form, and then call it’s save method.
def my_page(request):
if request.method == 'GET':
form1 = Form1()
form2 = Form2()
form3 = Form3()
else:
form1 = Form1(request.POST)
form2 = Form2(request.POST)
form3 = Form3(request.POST)
if form1.is_valid() and form2.is_valid() and form3.is_valid():
form1.save()
form2.save()
form3.save()
return render_to_response('my_page.html',
{'form1' : form1, 'form2' : form2, 'form3' : form3})
When posting to this action, the values input into any of these forms will be preserved after the post. If you want the values to not be preserved, you’ll need to create new instances of the forms that aren’t populated from the request.POST collection.
0👍
Jaime, please post some code snippets.
If you have distinct <form></form>
elements, you’re literally not passing the server any POST data from the other <form>
s so there’s no way to preserve that.
Consider combining your forms into one <form>
block.
With multiple django forms, you can ensure there are no name conflicts by using the prefix
argument to the form constructor.
Prefix: http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms
- [Django]-Remove a migration from south migration history
- [Django]-Download a file in django with a button using xmlhttprequest
- [Django]-TypeError Django
- [Django]-Django handle newlines in textarea