Skip to content

Commit eda2b45

Browse files
author
Richard Sarkis
authored
Merge pull request #2 from RocPy/fix-contact-form
Fix contact form
2 parents 31761a7 + dbf8ed4 commit eda2b45

File tree

2 files changed

+68
-53
lines changed

2 files changed

+68
-53
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# RocPy Website
2+
3+
This is the website for the Rochester Python "RocPy" Meetup, a Python user group in Rochester, NY. This website is statically generated with with Material for MkDocs and GitHub Actions. Additionally, we use Web3Forms for a simple submission to send its organizers an email.
4+
5+
## How to Contribute
6+
Pull requests are welcome! If you'd like to contribute to the website, please follow these steps:
7+
1. Clone the repository
8+
2. Create a new branch for your changes
9+
3. Make your changes
10+
4. Test your changes locally
11+
5. Push your changes to your fork
12+
6. Create a pull request
13+
14+
Your PR must be approved before merging. It will be reviewed for content, style, and adherence to the code of conduct. After merging, the GitHub Action defined in `.github/workflows/ci.yml` will publish the changes to RocPy's organization GitHub Page.

docs/contact.md

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
11
# Contact Us
22

3-
<script>
4-
const form = document.getElementById("contactForm");
5-
const submitBtn = document.getElementById("submitBtn");
6-
const messageStatus = document.getElementById("messageStatus");
7-
8-
form.addEventListener("submit", async function (event) {
9-
event.preventDefault();
10-
11-
// Clear old messages & set button state
12-
messageStatus.style.display = "none";
13-
messageStatus.classList.remove("success", "error");
14-
messageStatus.textContent = "";
15-
submitBtn.disabled = true;
16-
submitBtn.innerText = "Sending...";
17-
18-
const formData = new FormData(form);
19-
20-
try {
21-
const response = await fetch("https://api.web3forms.com/submit", {
22-
method: "POST",
23-
body: formData,
24-
});
25-
const json = await response.json();
26-
27-
if (json.success) {
28-
// Show success block
29-
messageStatus.textContent = "✓ Message sent successfully!";
30-
messageStatus.classList.add("success");
31-
messageStatus.style.display = "block";
32-
33-
// Optionally reset the form
34-
form.reset();
35-
} else {
36-
// Show error block
37-
messageStatus.textContent =
38-
"✗ An error occurred: " + (json.message || "Please try again later.");
39-
messageStatus.classList.add("error");
40-
messageStatus.style.display = "block";
41-
}
42-
} catch (error) {
43-
// Network or unexpected error
44-
messageStatus.textContent = "✗ Could not send message. " + error.message;
45-
messageStatus.classList.add("error");
46-
messageStatus.style.display = "block";
47-
} finally {
48-
submitBtn.disabled = false;
49-
submitBtn.innerText = "Send Message";
50-
}
51-
});
52-
</script>
53-
543
<form
554
action="https://api.web3forms.com/submit"
565
method="POST"
@@ -64,7 +13,7 @@
6413
<!-- <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE"> -->
6514

6615
<!-- 2) Optional honeypot field for spam control -->
67-
<input type="hidden" name="honeypot" value="" />
16+
<input type="checkbox" name="botcheck" class="hidden" style="display: none;">
6817

6918
<!-- Optional: But Recommended: To Prevent SPAM Submission. Make sure its hidden by default -->
7019
<input type="checkbox" name="botcheck" id="" style="display: none;">
@@ -73,7 +22,7 @@
7322
<!-- <input type="hidden" name="redirect" value="https://example.com/thank-you" /> -->
7423

7524
<!-- 4) Form "from" name -->
76-
<input type="hidden" name="RocPy Contact Noticfication" value="Mission Control">
25+
<input type="hidden" name="from_name" value="RocPy Contact Notification">
7726

7827
<div class="input-group">
7928
<label for="name">Name</label>
@@ -124,3 +73,55 @@
12473

12574
<!-- Hidden by default; shown on success or error -->
12675
<div id="messageStatus" class="message-status" style="display: none;"></div>
76+
77+
78+
<script>
79+
const form = document.getElementById("contactForm");
80+
const submitBtn = document.getElementById("submitBtn");
81+
const messageStatus = document.getElementById("messageStatus");
82+
83+
form.addEventListener("submit", async function (event) {
84+
event.preventDefault();
85+
86+
// Clear old messages & set button state
87+
messageStatus.style.display = "none";
88+
messageStatus.classList.remove("success", "error");
89+
messageStatus.textContent = "";
90+
submitBtn.disabled = true;
91+
submitBtn.innerText = "Sending...";
92+
93+
const formData = new FormData(form);
94+
95+
try {
96+
const response = await fetch("https://api.web3forms.com/submit", {
97+
method: "POST",
98+
body: formData,
99+
});
100+
const json = await response.json();
101+
102+
if (json.success) {
103+
// Show success block
104+
messageStatus.textContent = "✓ Message sent successfully!";
105+
messageStatus.classList.add("success");
106+
messageStatus.style.display = "block";
107+
108+
// Optionally reset the form
109+
form.reset();
110+
} else {
111+
// Show error block
112+
messageStatus.textContent =
113+
"✗ An error occurred: " + (json.message || "Please try again later.");
114+
messageStatus.classList.add("error");
115+
messageStatus.style.display = "block";
116+
}
117+
} catch (error) {
118+
// Network or unexpected error
119+
messageStatus.textContent = "✗ Could not send message. " + error.message;
120+
messageStatus.classList.add("error");
121+
messageStatus.style.display = "block";
122+
} finally {
123+
submitBtn.disabled = false;
124+
submitBtn.innerText = "Send Message";
125+
}
126+
});
127+
</script>

0 commit comments

Comments
 (0)