Skip to content

Instantly share code, notes, and snippets.

@danielthiel
Created March 2, 2014 11:46
Show Gist options
  • Save danielthiel/9305415 to your computer and use it in GitHub Desktop.
Save danielthiel/9305415 to your computer and use it in GitHub Desktop.
Mutliple forms in flask
<!-- put Forms here -->
<input type="submit" name="button" value="Save">
<input type="submit" name="button" value="Cancel">
# Source: http://flask.pocoo.org/mailinglist/archive/2010/9/12/flask-wtf-multiple-form-per-view/#d8cfeff63b89d028919d4617ed642d15
form1 = FormA(prefix="form1")
form2 = FormB(prefix="form2")
form3 = FormC(prefix="form3")
"""
Then, add a hidden field (or just check a submit field):
The prefix arg will ensure that each form has unique field names - so
form1's submit will be called "form1_submit".
"""
if request.form['button'] == 'Save':
if form1.validate_on_submit() and form1.submit.data:
do_save_form_1()
else:
do_cancel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment