跳转到内容
Formhook
← 返回博客

博客

如何为 GitHub Pages 添加联系表单

· 1 分钟阅读

<form action="https://formhook.app/f/fh_your-key" method="POST">
  <label>Email <input type="email" name="email" required></label>
  <label>Message <textarea name="message" required></textarea></label>
  <button type="submit">Send</button>
</form>
<a href="mailto:you@example.com">Email me</a>
<script>
document.querySelector("form").addEventListener("submit", async (e) => {
  e.preventDefault();
  const res = await fetch(e.target.action, {
    method: "POST",
    body: new FormData(e.target),
    headers: { Accept: "application/json" },
  });
  e.target.outerHTML = res.ok
    ? "<p>Thanks - message sent.</p>"
    : "<p>Something went wrong. Please email us directly.</p>";
});
</script>

一行代码上线可用的表单

欧盟托管,提交记录永久保存,所有套餐均支持推送通知。

免费开始

无需信用卡 · 阅读文档

继续阅读

Cookie 偏好设置

我们使用一个严格必要的会话 cookie 和无 cookie 的第一方分析。在您同意的情况下,我们还会使用 Google Analytics 来了解营销页面的流量。