Create a form that batches elements together with a "Submit" button.

A form is a container that visually groups other elements and widgets together, and contains a Submit button. When the form's Submit button is pressed, all widget values inside the form will be sent to Streamlit in a batch.

To add elements to a form object, you can use "with" notation (preferred) or just call methods directly on the form. See examples below.

Forms have a few constraints:

  • Every form must contain a st.form_submit_button.
  • st.button and st.download_button cannot be added to a form.
  • Forms can appear anywhere in your app (sidebar, columns, etc), but they cannot be embedded inside other forms.

For more information about forms, check out our blog post.

Function signature

st.form(key, clear_on_submit=False)

Parameters

key (str)

A string that identifies the form. Each form must have its own key. (This key is not displayed to the user in the interface.)

clear_on_submit (bool)

If True, all widgets inside the form will be reset to their default values after the user presses the Submit button. Defaults to False. (Note that Custom Components are unaffected by this flag, and will not be reset to their defaults on form submission.)

Was this page helpful?

editSuggest edits
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.