Create a Contact Form in Jekyll Website
,Contact forms in Jekyll should be different from normal php forms because Jekyll doesn’t support php. Jekyll blog is static, so we should use forms that work for static sites. Here is a simple form that works on any Jekyll blog.
When I moved one of my blogs from WordPress to Jekyll, I faced a big problem. Which was - how to add a form to Jekyll website which is static?! Generally, the backbone of forms is the php
code which takes the data and sends it to the defined email address. Jekyll being static cannot perform any server side execution. So we cannot use php
for forms.
- why use a form?
- Form on Jekyll
- Step 1: Create a form
- Step 2: Make it work
- Step 3: Custom thank-you page
- Step 4: Security from bots
- Step 5: Secure your email
- Step 6: Ultra security
- Things to keep in mind
why use a form?
Form is a way to interact with the users. Providing personal emails and phone numbers can lead to receiving a lot of spam. This is the reason why no famous website includes their personal emain or phone number.
Forms on the other hand are very useful in such cases where you do not want to give out your personal details. It is a better way to interact with users.
Forms can be a contact form, subscription form, sign up form, complaint form, survey form etc., where the user enters some data and that reaches the site owner to make further decisions or conclusion based on the entry.
Form on Jekyll
There are few solutions to create a form in Jekyll blog.
Formspree has a restriction 1000 entries/month. It is more than enough for a starter like myself. You can choose Gold membership for more entries and gain access to Formspree database.
But, I prefer SimpleForm because one form created in simple form can be used on any page without verification. So to know how to set up simpleform, read: How to create a form using SimpleForm
I’m going to explain the simplest among the two - Formspree.
Step 1: Create a form
Let’s create a simple form and make it work. I will have only two options for user input - Name and Email. Copy and paste the below form code inside the body tag (or wherever you want the form to be).
Keep this repository open. Here I’ve a simple form created using Formspree.
So the output should look something like this.
Step 2: Make it work
If you see the code for the form, action and method are empty. Formspree suggests you to add an action and method in this format.
Whenever a user submits his name and email, the data will be sent to formspree.io
website and then formspree sends it back to your email with the details.
Try to enter something and see if you receive the mail. For the first time, you have to verify your email address. After that, you can receive mails without any hassle.
This is the brief process of making a form in GitHub pages website. What if you want to redirect users to a custom web page once they are done submitting the form on Jekyll blog or GitHub pages website?
Step 3: Custom thank-you page
After the submission, users are redirected to a formspree thank you page by default. But if you want it to be your own custom thank you page then you can do so adding this code.
I have a working example here - nallikayi contact. Once you fill all the details you will be redirected to a custom page with a thank you message.
Make sure you create a thank you page in Github-pages with the name thanks.html
.
Step 4: Security from bots
If your form is not secure, it may result in receiving spam emails. This is because an email harvester can pick up your email from the form code.
To fool the bots, Formspree has provided an option called _gotcha
. This is an input field only visible to bots but not to users. If an entry is made in this invisible field, that means that someone can see through your invisible element! Must be a bot!! This form entry is neglected.
Step 5: Secure your email
When you mention your email in clear text inside your form, email harvesting bots can easily capture it. Which may result in receiving a lot of spam emails. So you can use this code to inject your email. The code will join the strings to a meaningful email address. But bots will not recognize this as an email.
Step 6: Ultra security
In step 5, your email cannot be read by a bot but a human can obviously connect the dots and find out the email address. If you are paranoid about giving out your email in any way then use this method.
Encode the whole form!
Log on to Enkoder and copy paste your entire Formspree form and hit submit. This tool will encode your data to something like this.
You don’t recognize anything. Do you?
It is actually
This works like a charm. You are not only cheating bots but also human email harvesters. It is not impossible to decode this but it is hard!
Things to keep in mind
Be careful not to include your personal email in form action as it is easily visible when website source is viewed. You can include an alternative email which forwards emails to your personal email.
Also, I don’t recommend using formspree if you are asking your users for any sensitive data because a copy of it is saved in the formspree database. But for general non-sensitive data submission, formspree works like a charm.
Here is a video demonstration on how to set up formspree form on static websites. Don’t forget to leave the link of your website with newly created form, in the comment section.
Thanks for reading!