Syntax: `{% get_fieldset list,of,fields as new_form_object from original_form %}`
Example:
{% load fieldsets %}
...
<fieldset id="contact_details">
<legend>Contact details</legend>
<ul>
{% get_fieldset first_name,last_name,email,cell_phone as personal_fields from form %}
{{ personal_fields.as_ul }}
</ul>
</fieldset>
<fieldset>
<legend>Address details</legend>
<ul>
{% get_fieldset street_address,post_code,city as address_fields from form %}
{{ address_fields.as_ul }}
</ul>
</fieldset>
Django administration provides three buttons for submitting the currently edited object. Each of them has a unique name and depending on the name that is sent to the server, the specific action is performed. I see this as an ugly solution and prefer to have a choice field in the form which would render as submit buttons with different values. Then the values would be checked instead of the names. Therefore, I created the `MultipleSubmitButton` widget. When `<input type="submit" value="Go" />` is used, the value sent to the server always matches the text on the button, but if `<button type="submit" value="go">Go</button>`, the value and the human representation might differ.
To use the `MultipleSubmitButton` widget, pass it to the widget parameter of a `ChoiceField` like this:
SUBMIT_CHOICES = (
('save', _("Save")),
('save-add', _("Save and Add Another")),
)
class TestForm(forms.Form):
do = forms.ChoiceField(
widget=MultipleSubmitButton,
choices=SUBMIT_CHOICES,
)
When you print `{{ form.do }}` in the template, the following HTML will be rendered:
<ul>
<li><button type="submit" name="do" value="save">Save</button></li>
<li><button type="submit" name="do" value="save-add">Save and Add Another</button></li>
</ul>
When you submit this form and check the validity of it, `form.cleaned_data['do']` will return "save" or "save-add" depending on the submit button clicked.