# How do you change the contents of a form based on radio buttons?

**URL:** <https://discuss.streamlit.io/t/how-do-you-change-the-contents-of-a-form-based-on-radio-buttons/73098>\
**Category:** Using Streamlit\
**Tags:** discussion\
**Created:** [June 21, 2024, 7:41pm UTC](https://discuss.streamlit.io/t/how-do-you-change-the-contents-of-a-form-based-on-radio-buttons/73098 "2024-06-21T19:41:00Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![edsaac](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/edsaac/32/47599_2.png) [@edsaac](https://discuss.streamlit.io/u/edsaac)\
**Post date:** [June 24, 2024, 12:37pm UTC](https://discuss.streamlit.io/t/how-do-you-change-the-contents-of-a-form-based-on-radio-buttons/73098/6 "2024-06-24T12:37:14Z")

</div>

> [@plokmijn12345](#):
>
> I then get an error of “cannot access local variable ‘use\_case’ where it is not associated with a value” when checking if `use_case == "complex"`.

You are trying to use a variable that has not been declared yet. The use of containers helps with placing elements in the page in an arbitrary order, but the code still runs from top to bottom.

The only change you need is to place the st.empty containers inside the st.form and put the if logic **outside** the form, where the empty containers are actually filled up.

> **Code for the screen recording from before:**
>
> ```python
> import streamlit as st
> 
> with st.form("form"):
> first = st.text_input("First")
> second = st.text_input("Second")
> 
> placeholder_radio = st.empty()
> placeholder_additional_inputs = st.empty()
> 
> submit_button = st.form_submit_button("Submit")
> 
> with placeholder_radio:
> show_questions = st.radio("Show questions", ("No", "Yes"))
> 
> with placeholder_additional_inputs.container():
> if show_questions == "Yes":
> third = st.text_input("Third")
> fourth = st.text_input("Fourth")
> 
> if submit_button:
> " **You submitted:**"
> if show_questions == "Yes":
> st.write(first, second, third, fourth)
> else:
> st.write(first, second)
> 
> ```

---

_[View the full topic](https://discuss.streamlit.io/t/how-do-you-change-the-contents-of-a-form-based-on-radio-buttons/73098)._
