Text Inputs in a Form not Working

I am trying to run a function based on folder locations provided by text_inputs made within a form.

It is currently locally hosted, I am hoping to deploy in the future.
Python 3.12.8
streamlit==1.42.1

The text inputs only appear after a button is clicked.

The text inputs do not seem to return the data input into the form. When I print them, they print nothing in the command prompt.

Here is the code:

def custom():

with st.form('custom'):
    data_path = st.text_input(
        "Enter the folder where the files are saved:"
    )

    folder_path = st.text_input(
        "Enter the folder path where you want to save the file:"
    )

    file_name = st.text_input(
        "Enter the filename for the file (should end in .xlsx):"
    )

    file_name = folder_path +'\\'+ file_name

    st.header("Test Type:")

    measurements = [
        "Shear",
        "Tensile"
    ]

    container = st.container()

    test_type = container.selectbox("Test Type:", measurements)

    st.header("Options")
    avg_data = st.checkbox("Average Data")

    st.form_submit_button('Run Model', on_click = run_custom, args = (test_type, data_path, file_name, avg_data))

Update:
If I move the form out from behind the button, it works.

If you wanted to keep the form setup, all streamlit widgets require using session_state to access their inputs in a callback

In other words, for your program you would need keys for each input, such as:

    data_path = st.text_input(
        "Enter the folder where the files are saved:",
        key='data_path'
    )

and then access that input in the callback like this:

def run_custom():
    data_path = st.session_state.data_path