transpolymer commited on
Commit
67ef359
·
verified ·
1 Parent(s): 7b3033f

Update contact.py

Browse files
Files changed (1) hide show
  1. contact.py +50 -53
contact.py CHANGED
@@ -1,56 +1,53 @@
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
- # Load EmailJS credentials securely from secrets.toml
5
- public_key = st.secrets["emailjs"]["public_key"]
6
- service_id = st.secrets["emailjs"]["service_id"]
7
- template_id = st.secrets["emailjs"]["template_id"]
8
-
9
- st.title("📬 Contact Us")
10
- st.write("Feel free to reach out to us by filling the form below.")
11
-
12
- # Contact form using Streamlit
13
- with st.form(key="contact_form"):
14
- name = st.text_input("Your Name")
15
- email = st.text_input("Your Email")
16
- message = st.text_area("Your Message")
17
- submit_button = st.form_submit_button("Send")
18
-
19
- if submit_button:
20
- if name and email and message:
21
- st.success("Sending your message...")
22
-
23
- js_code = f"""
24
- var templateParams = {{
25
- name: "{name}",
26
- email: "{email}",
27
- message: `{message}`
28
- }};
29
-
30
- emailjs.send("{service_id}", "{template_id}", templateParams, "{public_key}")
31
- .then(function(response) {{
32
- console.log("SUCCESS!", response.status, response.text);
33
- window.parent.postMessage({{"type": "success", "message": "Email sent successfully!"}}, "*");
34
- }}, function(error) {{
35
- console.log("FAILED...", error);
36
- window.parent.postMessage({{"type": "error", "message": "Failed to send email."}}, "*");
37
- }});
38
- """
39
-
40
- components.html(f"""
41
- <html>
42
- <head>
43
- <script src="https://cdn.jsdelivr.net/npm/emailjs-com@2.6.4/dist/email.min.js"></script>
44
- <script>
45
- (function() {{
46
- emailjs.init("{public_key}");
47
- {js_code}
48
- }})();
49
- </script>
50
- </head>
51
- <body></body>
52
- </html>
53
- """, height=0)
54
-
55
- else:
56
- st.error("Please fill out all the fields.")
 
1
  import streamlit as st
2
  import streamlit.components.v1 as components
3
 
4
+ def show():
5
+ st.title("📬 Contact Us")
6
+ st.write("Feel free to reach out to us by filling the form below.")
7
+
8
+ public_key = st.secrets["emailjs"]["public_key"]
9
+ service_id = st.secrets["emailjs"]["service_id"]
10
+ template_id = st.secrets["emailjs"]["template_id"]
11
+
12
+ with st.form(key="contact_form"):
13
+ name = st.text_input("Your Name")
14
+ email = st.text_input("Your Email")
15
+ message = st.text_area("Your Message")
16
+ submit_button = st.form_submit_button("Send")
17
+
18
+ if submit_button:
19
+ if name and email and message:
20
+ st.success("Sending your message...")
21
+
22
+ js_code = f"""
23
+ var templateParams = {{
24
+ name: "{name}",
25
+ email: "{email}",
26
+ message: `{message}`
27
+ }};
28
+ emailjs.send("{service_id}", "{template_id}", templateParams, "{public_key}")
29
+ .then(function(response) {{
30
+ console.log("SUCCESS!", response.status, response.text);
31
+ window.parent.postMessage({{"type": "success", "message": "Email sent successfully!"}}, "*");
32
+ }}, function(error) {{
33
+ console.log("FAILED...", error);
34
+ window.parent.postMessage({{"type": "error", "message": "Failed to send email."}}, "*");
35
+ }});
36
+ """
37
+
38
+ components.html(f"""
39
+ <html>
40
+ <head>
41
+ <script src="https://cdn.jsdelivr.net/npm/emailjs-com@2.6.4/dist/email.min.js"></script>
42
+ <script>
43
+ (function() {{
44
+ emailjs.init("{public_key}");
45
+ {js_code}
46
+ }})();
47
+ </script>
48
+ </head>
49
+ <body></body>
50
+ </html>
51
+ """, height=0)
52
+ else:
53
+ st.error("Please fill out all the fields.")