Error with using different keys on streamlit form

Hi I have encountered an error where you cannot specify another key for the form widgets.

Here is the method I use to generate keys for the form widgets which works on all other streamlit widgets I used in my application
image

You can provide only one key. Why do you want to give two keys to the same form?

Hey @luqmannur.ai!

I understand the confusion, a lot of Streamlit commands have arguments label and key… but st.form() doesn’t have any label! In fact, key is a positional argument in st.form(), and is even the very first argument that is expected.

Meaning whenever you call st.form("Chat Feedback"), this is understood as calling st.form(key="Chat Feedback")! So using st.form("Chat Feedback", key=form_key) throws an exception because it is understood as st.form(key="Chat Feedback", key=form_key)

Probably if you are creating multiple forms and want to make sure keys don’t collide, you may want to switch your code to simply be:

with st.form(form_key):
    st.write("Feedback form")
    ...

Hope that helps :upside_down_face:

Hi arnaud, thanks for the reply and helping a new learner out.