Say I have a form like:
class GeneralForm(forms.Form): field1 = forms.IntegerField(required=False) field2 = forms. IntegerField(required=False)
And I want to show it twice on a page within one form tag each time with a different prefix e.g.,:
rest of page ... <form ..> GeneralForm(data,prefix='form1').as_table() GeneralForm(data,prefix='form2').as_table() <input type='submit' /> </form> rest of page ...
When the user submits this, how do I get the submitted form back into two separate forms to do validation, and redisplay it?
This was the only documentation I could find and it’s peckish.
You process each form as you normally would, ensuring that you create instances which have the same prefixes as those used to generate the form initially.
Here’s a slightly awkward example using the form you’ve given, as I don’t know what the exact use case is:
Here’s some real-world sample code which demonstrates processing forms using the prefix:
http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/