# Form\_submit\_button

**URL:** <https://discuss.streamlit.io/t/form-submit-button/22566>\
**Category:** Using Streamlit\
**Created:** [February 27, 2022, 4:56pm UTC](https://discuss.streamlit.io/t/form-submit-button/22566 "2022-02-27T16:56:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piero\_Chiacchiaretta](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/piero_chiacchiaretta/32/13799_2.png) [@Piero\_Chiacchiaretta](https://discuss.streamlit.io/u/Piero_Chiacchiaretta)\
**Post date:** [February 27, 2022, 4:56pm UTC](https://discuss.streamlit.io/t/form-submit-button/22566/1 "2022-02-27T16:56:30Z")

</div>

Hi everybody,

How do I make the “Submit” button become selectable only after copying all the texts?

this is my code

thanks

```auto
import streamlit as st
import pymongo

# Initialize connection.
client = pymongo.MongoClient(**st.secrets["mongo"])

db = client.streamlit
collection = db.test

# Using the "with" syntax
with st.form(key='my_form'):    
    first_name = st.text_input(label='Enter first name', key="first_name")
    last_name = st.text_input(label="Enter last name", key="last_name")
    submit_button = st.form_submit_button(label='Submit')

#st.write('Press submit to have your name printed below')

# if submit_button:
# st.write(f'First name: {first_name}')
# st.write(f'Last name: {last_name}')

document = {
    "name": f'{first_name}',
    "last_name": f'{last_name}'
}

collection.insert_one(document)

```

---

<div class="post-metadata">

**Author:** ![Shawn\_Pereira](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/shawn_pereira/32/44502_2.png) [@Shawn\_Pereira](https://discuss.streamlit.io/u/Shawn_Pereira)\
**Post date:** [February 27, 2022, 6:28pm UTC](https://discuss.streamlit.io/t/form-submit-button/22566/2 "2022-02-27T18:28:44Z")

</div>

Hi @Piero_Chiacchiaretta , I don’t think you can do this with forms. You can try this:

1. Delete the line: with st.form(key=‘my\_form’):
2. After getting the value of first\_name &  
last\_name, do any validation of these inputs as required (eg. Checking if they both contain valid data, etc.)
3. Change the line: submit\_button = st.form\_submit\_button to submit\_button = st.button and add the disabled parameter depending upon the result of step 2 above. You can refer this in the at.button documentation
4. This way, only if valid data is entered, the button will be selectable. You can then proceed further as required

Cheers

---

<div class="post-metadata">

**Author:** ![Piero\_Chiacchiaretta](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/piero_chiacchiaretta/32/13799_2.png) [@Piero\_Chiacchiaretta](https://discuss.streamlit.io/u/Piero_Chiacchiaretta)\
**Post date:** [February 27, 2022, 10:48pm UTC](https://discuss.streamlit.io/t/form-submit-button/22566/3 "2022-02-27T22:48:15Z")

</div>

thank you for the suggestion @Shawn_Pereira work. You now also how is possible clean the form after push the button ?

---

<div class="post-metadata">

**Author:** ![snehankekre](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/snehankekre/32/6504_2.png) [@snehankekre](https://discuss.streamlit.io/u/snehankekre)\
**Post date:** [February 28, 2022, 5:10am UTC](https://discuss.streamlit.io/t/form-submit-button/22566/4 "2022-02-28T05:10:18Z")

</div>

> [@Piero\_Chiacchiaretta](#):
>
> how is possible clean the form after push the button ?

You can set the `clear_on_submit` parameter for [`st.form()`](https://docs.streamlit.io/library/api-reference/control-flow/st.form) to True. All widgets inside the form will be reset to their default values after the user presses the Submit button:

```python
with st.form(key='my_form', clear_on_submit=True):  

```

_Happy Streamlit-ing!_ 🎈  
_Snehan_

---

<div class="post-metadata">

**Author:** ![Piero\_Chiacchiaretta](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/piero_chiacchiaretta/32/13799_2.png) [@Piero\_Chiacchiaretta](https://discuss.streamlit.io/u/Piero_Chiacchiaretta)\
**Post date:** [February 28, 2022, 6:25am UTC](https://discuss.streamlit.io/t/form-submit-button/22566/5 "2022-02-28T06:25:28Z")

</div>

Thanks, but with this method can’t make the “Submit” button become selectable only after insert all the texts in form.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [February 28, 2023, 6:25am UTC](https://discuss.streamlit.io/t/form-submit-button/22566/6 "2023-02-28T06:25:44Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
