Jekyll
A Jekyll include that renders an Ikiform form from _config.yml, with redirects that work on GitHub Pages and custom domains.
Jekyll sites are static, which suits a plain form post. Keep the form in an include so every page uses the same markup and the form id lives in one place.
Set it up
Add the settings to _config.yml
_config.yml url: "https://example.com" ikiform: form_id: frm_xxxxxxxxxxxxxxxx thanks: /thanks/The include builds the redirect with
absolute_url, which needsurl. Without it, the redirect is only a path, and Ikiform ignores anything that isn't a fullhttps:URL. On a GitHub Pages project site, also setbaseurl: /repo;absolute_urladds it for you.Create the include
_includes/ikiform-form.html {%- assign form_id = include.form_id | default: site.ikiform.form_id -%} {%- assign thanks = include.thanks | default: site.ikiform.thanks -%} <form class="ikiform" action="https://ikiform.com/f/{{ form_id }}" method="post"> <label>Email <input name="email" type="email" autocomplete="email" required></label> <label>Message <textarea name="message" rows="5"></textarea></label> {%- if include.subject %} <input type="hidden" name="_subject" value="{{ include.subject | escape }}"> {%- endif %} {%- if thanks %} <input type="hidden" name="_redirect" value="{{ thanks | absolute_url }}"> {%- endif %} <input name="_gotcha" type="text" tabindex="-1" autocomplete="off" hidden> <button type="submit">{{ include.button | default: "Send" }}</button> </form>Use it
contact.md --- layout: page title: Contact --- Questions about pricing? Write to us. {% include ikiform-form.html subject="Pricing question" %}The include works in pages, posts and layouts. Pass
form_idto use another form,thanksfor another redirect, andbuttonfor the button text.Add the thank-you page
thanks.md --- layout: page title: Thanks permalink: /thanks/ --- Thanks, we got your message.
_redirect is followed only when the form has allowed domains that include your site. See Rules for _redirect.
Allowed domains
GitHub Pages is the usual host for Jekyll, so you'll often need two entries: the github.io host and your custom domain.
| Where the form runs | Add to Allowed domains |
|---|---|
bundle exec jekyll serve | localhost. It matches http://localhost:4000: Ikiform compares the host name only, never the port. |
| GitHub Pages | username.github.io. Project sites at username.github.io/repo use the same host, so one entry covers them all. |
| Custom domain on GitHub Pages | example.com, which also covers www.example.com |
| Netlify | your-site.netlify.app. Deploy previews (deploy-preview-12--your-site.netlify.app) and branch deploys (branch--your-site.netlify.app) are not subdomains of it, so add the exact preview host while you test one. |
- Never add
github.ioon its own. Every site on that host would match, including other people's.
Test checklist
- Run
bundle exec jekyll serveand view the page source. Theactionshould end in your form id. - Submit locally. You'll land on Ikiform's thank-you page:
jekyll servesetsurltohttp://localhost:4000, andhttp:redirects aren't followed. - Push, wait for the Pages build, and submit from
username.github.io. Confirm the submission isn't marked spam. - Submit on your custom domain and confirm you land on
/thanks/.
Troubleshooting
| What you see | Why | Fix |
|---|---|---|
Could not locate the included file 'ikiform-form.html' | The file isn't in _includes, or the name differs | Move it to _includes/ikiform-form.html. |
Ikiform's thank-you page instead of /thanks/ on the live site | url is missing from _config.yml, or the form has no allowed domains | Set url to your https: address and add your domain. |
404 not_found after submit | site.ikiform.form_id is empty, so the action ends in /f/ | Check the indentation under ikiform: in _config.yml. |
Submissions arrive under the spam filter with origin_mismatch | The page that posted isn't on the form's allowed domains | Add the host from the table above. With Reject chosen, the same posts get 403 origin_not_allowed instead. |