Form's submit button does not work as expected

Hi everyone,

I am developing a NLP app which will process an input csv file and my intention is to use form on the output and let users adjust this output before downloading it. The problem I have is that when calling

submit_button = st.form_submit_button('Save')

if submit_button:
   st.write("Form submitted! - Test form")

It does not even write “Form submitted! - Test form” but only reruns the whole script. I understand that this should be expected when changing any input widget or clicking on any buttons. However, I saw the example in this blog post wrote by Streamlit team and I can see that it is possible to do things the way I did.

I also tried using the same code in the blog post:

form = st.form(key='my-form')
name = form.text_input('Enter your name')
submit = form.form_submit_button('Submit')

st.write('Press submit to have your name printed below')

if submit:
    st.write(f'hello {name}')

but the result was the same, nothing printed out and the script reruns… I tried switching from my current version 1.1.0 to 0.81.0 (the version mentioned in the blog) but still no luck!

Please give me some instructions if you know how to fix this. I really need help from the Streamlit experts here in the community :innocent:

Hi, I think you missed the “with”, try to add it like this:

with st.form("my_form"):
     st.write("Inside the form")
     submitted = st.form_submit_button("Submit")
     if submitted:
         st.write("you clicked the submit button")

let me know it can help you or not.