Spaces:
Running
Running
Update contact.py
Browse files- 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 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
st.
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
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.")
|
|
|
|
|
|