When Using Forms, How to Combine Responses With Imported Data

My Streamlit app uses a form to get feedback from a user. The questions are taken from a pandas dataframe, and when the user click’s Submit , the questions plus responses are stored in a list that is preserved using st.session_state.

There is an interesting problem that has emerged. When using forms, the user responses don’t get assigned to their variables (e.g. question1 = text_input()) until after a user submits. But, the question that the user is seeing on their screen will reset when the user hits submit, so there’s a hard to see problem: When you append the question/response to a list, it’s the wrong question . The reason is that when you hit ‘submit’ the script reruns, and therefore a new question from the dataframe is grabbed and saved with the responses.

Does anyone know a way around this problem?

Hey @methomas2001 ! I had the same issue with preserving responses in a Streamlit form. I came across this platform called SuperEngineer, and it gave me the perfect solution just by describing my problem. It handled the form reset issue and kept the questions correctly paired with the responses. Definitely worth checking out!

Here’s the reference link for the project: Streamlit Code Gen. Check out the screenshots below!