Multiple forms in a single page using flask and WTForms -
i have multiple form on same page send post request same handler in flask.
i generating forms using wtforms.
what best way identify form submitted ?
i using action="?form=oneform"
. think there should better method achieve same?
i've been using combination of 2 flask snippets. the first adds prefix form , check prefix validate_on_submit(). i use louis roché's template determine buttons pushed in form.
to quote dan jacob:
example:
form1 = forma(prefix="form1") form2 = formb(prefix="form2") form3 = formc(prefix="form3")
then, add hidden field (or check submit field):
if form1.validate_on_submit() , form1.submit.data:
to quote louis roché's:
i have in template :
<input type="submit" name="btn" value="save"> <input type="submit" name="btn" value="cancel">
and figure out button passed server side have in views.py file:
if request.form['btn'] == 'save': something0 else: something1
Comments
Post a Comment