A contact form for a GitHub Pages site
GitHub Pages serves your HTML and nothing else, so a form has nowhere to send its messages. Point it at FormHaven and every message is spam filtered, stored in Germany and emailed to you, with no server and no GitHub Action.
14 days free, no card. Paste the address where the code says YOUR_FORM_ID.
<form action="https://formhaven.net/f/YOUR_FORM_ID" method="POST">
<label>Your name <input type="text" name="name" required></label>
<label>Your email <input type="email" name="email" required></label>
<label>Message <textarea name="message" required></textarea></label>
<input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off">
<input type="hidden" name="_next" value="https://USERNAME.github.io/REPOSITORY/thanks.html">
<button type="submit">Send message</button>
</form>
Set it up
-
1
Know why it needs a backend
GitHub calls Pages "a static site hosting service that takes HTML, CSS, and JavaScript files". Nothing runs when a visitor presses Send, so the form posts to FormHaven instead.
-
2
Create a form in FormHaven
Sign up, press New form and copy its address. It looks like https://formhaven.net/f/YOUR_FORM_ID.
-
3
Paste the form and push
Put your address in the action, change USERNAME and REPOSITORY in _next to your own, add a thanks.html page, then commit and push as usual.
-
4
Send a test
Open your github.io page once GitHub has published it, fill in the form and check your inbox.
Send visitors back to the right page
A project site lives under its repository name, so "/thanks.html" opens on the wrong address. Include the repository in the path, or write the full address. A user or organisation site at USERNAME.github.io, or a site on your own domain, can use the short form. FormHaven only follows _next to the site the form was sent from.
<!-- project site: USERNAME.github.io/REPOSITORY -->
<input type="hidden" name="_next" value="/REPOSITORY/thanks.html">
<!-- user site, or your own domain -->
<input type="hidden" name="_next" value="/thanks.html">
In a Jekyll site
GitHub Pages builds Jekyll sites by default. Save the form as an include and put {% include contact.html %} on your contact page. On a project site, set baseurl: "/REPOSITORY" in _config.yml, as Jekyll sites on GitHub Pages usually do. site.baseurl then fills in the repository path, so the same file works on github.io and on your own domain.
<form action="https://formhaven.net/f/YOUR_FORM_ID" method="POST">
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<input type="text" name="_gotcha" style="display:none" tabindex="-1" autocomplete="off">
<input type="hidden" name="_next" value="{{ site.baseurl }}/thanks/">
<button type="submit">Send</button>
</form>
Stop bots that skip the hidden field
Turn on the bot check in the form's settings and add this line once to the page, or to your Jekyll layout. Visitors see nothing, and it sets no cookies.
<script src="https://formhaven.net/bot-check.js" async></script>
Questions about this setup
- Do I need a GitHub Action or a serverless function?
- No. The form posts straight from the visitor's browser to FormHaven. Your repository only holds the HTML.
- Does it work with a custom domain?
- Yes. The form address does not care where the page is hosted. If you limit the form to your own domains in its settings, list the custom domain and the github.io address you still use.
- How do I answer a message?
- Press Reply in the email. The address the visitor typed in the email field is set as the reply address.
- Can my client get the messages instead of me?
- Yes. Add up to 5 more addresses to the form. Each one confirms by a link first, and their copy carries no FormHaven branding. You can turn your own copy off.
- Where is the data stored?
- On our server at Hetzner in Falkenstein, Germany, for 1 to 365 days as you choose per form, or not at all. A data processing agreement covers every account.
More to read
Get your form address in a minute
14 days free, no card. Then €1 per form a month, €0.50 from the 11th form.