Skip to content Skip to sidebar Skip to footer

How To Get The Name Of A Submitted Form In Flask?

I'm building a website using Flask, and on one page I've got two forms. If there's a POST, I need to decide which form is being posted. I can of course deduct it from the fields th

Solution 1:

There is no 'name of the form'. That information is not sent by the browser; the name attribute on <form> tags is meant to be used solely on the browser side (and deprecated to boot, use id instead).

You could add that information by using a hidden field, but the most common way to distinguish between forms posting to the same form handler is to give the submit button a name:

<submit name="form1" value="Submit!"/>

and

if 'form1' in request.form:

but you could also use a <input type="hidden"> field to include the means to distinguish between forms.


Post a Comment for "How To Get The Name Of A Submitted Form In Flask?"