|
| 1 | +# Contact Us |
| 2 | + |
| 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 | + |
| 54 | +<form |
| 55 | + action="https://api.web3forms.com/submit" |
| 56 | + method="POST" |
| 57 | + class="contact-form" |
| 58 | + id="contactForm" |
| 59 | +> |
| 60 | + <!-- 1) Your Access Key from Web3Forms --> |
| 61 | + <input type="hidden" name="access_key" value="9c04327a-dea1-4938-8b84-37de91941a7b" /> |
| 62 | +
|
| 63 | + <!-- Uncomment below to test emails without sending them --> |
| 64 | + <!-- <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE"> --> |
| 65 | + |
| 66 | + <!-- 2) Optional honeypot field for spam control --> |
| 67 | + <input type="hidden" name="honeypot" value="" /> |
| 68 | + |
| 69 | + <!-- Optional: But Recommended: To Prevent SPAM Submission. Make sure its hidden by default --> |
| 70 | + <input type="checkbox" name="botcheck" id="" style="display: none;"> |
| 71 | + |
| 72 | + <!-- 3) Remove the redirect if you want a single-page (AJAX) submission --> |
| 73 | + <!-- <input type="hidden" name="redirect" value="https://example.com/thank-you" /> --> |
| 74 | + |
| 75 | + <!-- 4) Form "from" name --> |
| 76 | + <input type="hidden" name="RocPy Contact Noticfication" value="Mission Control"> |
| 77 | + |
| 78 | + <div class="input-group"> |
| 79 | + <label for="name">Name</label> |
| 80 | + <input |
| 81 | + type="text" |
| 82 | + name="name" |
| 83 | + id="name" |
| 84 | + placeholder="Your Name" |
| 85 | + required |
| 86 | + /> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div class="input-group"> |
| 90 | + <label for="email">Email</label> |
| 91 | + <input |
| 92 | + type="email" |
| 93 | + name="email" |
| 94 | + id="email" |
| 95 | + placeholder="Your Email" |
| 96 | + required |
| 97 | + /> |
| 98 | + </div> |
| 99 | + |
| 100 | + <div class="input-group"> |
| 101 | + <label for="subject">Subject</label> |
| 102 | + <input |
| 103 | + type="text" |
| 104 | + name="subject" |
| 105 | + id="subject" |
| 106 | + placeholder="Subject" |
| 107 | + required |
| 108 | + /> |
| 109 | + </div> |
| 110 | + |
| 111 | + <div class="input-group"> |
| 112 | + <label for="message">Message</label> |
| 113 | + <textarea |
| 114 | + name="message" |
| 115 | + id="message" |
| 116 | + rows="5" |
| 117 | + placeholder="Your message" |
| 118 | + required |
| 119 | + ></textarea> |
| 120 | + </div> |
| 121 | + |
| 122 | + <button type="submit" id="submitBtn">Send Message</button> |
| 123 | +</form> |
| 124 | + |
| 125 | +<!-- Hidden by default; shown on success or error --> |
| 126 | +<div id="messageStatus" class="message-status" style="display: none;"></div> |
0 commit comments