I’m trying to create forms, each by using a side button.
When I do this, the form pops up, but the code that should occur AFTER the submit button is pressed is executed anyway. This makes it seem that the submit button does not wait and is set to FALSE.
Here is my simple code:
import streamlit as st
sideb = st.sidebar
formbtn1 = sideb.button("Click to start the form")
if formbtn1:
sideb = st.sidebar
with st.form(key='my-form', clear_on_submit=True):
name = st.text_input('Enter your name')
submit = st.form_submit_button('Submit')
st.write('Press submit to have your name printed below')
if submit:
st.write(f'hello {name}')
st.write('This is the text that should occur after the submit')
What happens after the button is pressed to start the form, it’s as if it doesn’t wait for the submit_button to be pressed, and passes through the code and immediately writes “This is the text that should occur after the submit”. Also, when I do enter my name and hit “Submit”, nothing happens and all is lost.
Very stubborn issue. Any help would be appreciated.