visit
1. Setting up your Ghost Site
As first step, we will install the Ghost-CLI, which is a command line tool to help you get Ghost installed and configured for use, quickly and easily.npm install ghost-cli@latest -g
ghost install local
Once the install is finished you'll be able to access your new site on
//localhost:2368
and //localhost:2368/ghost
to access Ghost Admin. It will come with a default Ghost theme called . The admin will look like below:2. Creating a custom page template
With our Ghost site created and running, we can now start creating a custom post template.
custom-page-with-getform.hbs
and open it in your favorite code editor. We will be using this template for our reusable contact form setup.{{!< page}}
{{#contentFor "form-area"}}
<!-- form here -->
{{/contentFor}}
The line
{{!< page}}
will take the original page.hbs
template in the theme and insert everything below it into the page template.3. Define a content block
In order for the code in our new custom template to be inserted in the right place we need to define a content block. A content block can be defined using the
{{#contentFor "example"}}...{{/contentFor}}
helper, as shown in the code sample above.Open the page.hbs template in your code editor and locate a place in which you want the form to appear and add the following:{{{block "form-area"}}}
Since the block has been referenced anything between the
{{#contentFor "form-area"}}...{{/contentFor}}
block helper will be inserted wherever the code has been placed at.4. Create your Ghost contact form using Getform
Getform is a form backend service for static sites and blogs. You can or login with your existing account to Getform.
After you login to your account, Click to “+” button on your forms dashboard page to create a new form then name it e.g. “Ghost Blog Contact Form" and copy the unique form endpoint that belongs to the form you have just created. With that unique form endpoint add the code block below between the “contentFor” block:<form class="contact-form" action="//getform.io/f/9de64cfa-0a4a-4fd2-b385-687e2059cae6" method="POST>
<label for="full-name">Name</label>
<input type="text" name="name" id="full-name" placeholder="First and Last" required>
<label for="email-address">Email Address</label>
<input type="email" name="_replyto" id="email-address" placeholder="Your email address" required>
<label for="message">Your Message</label>
<textarea rows="5" name="message" id="message" placeholder="Your message" required></textarea>
<input type="submit" value="Submit">
</form>
action
attribute of the form tag.enctype='multipart/form-data'
attribute to your form tag as well as the file input. You can check more setup details .5. Styling your contact form
Next we need to add some style and layout to our form. Depending on your theme, you might already have some default styles for form elements. If you're using Casper, like in this tutorial, you can use the following CSS:.contact-form {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 0.2em 1em;
}
.contact-form input,
.contact-form textarea {
width: 100%;
padding: 0.4em 0.6em 0.5em;
color: #111;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Open Sans, Helvetica Neue, sans-serif;
font-size: 0.95em;
}
.contact-form input:focus,
.contact-form textarea:focus {
outline: 1px solid #3eb0ef;
outline-offset: -1px;
}
.contact-form label[for="full-name"],
.contact-form label[for="email-address"] {
order: -1;
}
.contact-form input {
order: 0;
margin-bottom: 0.6em;
}
.contact-form label[for="message"],
.contact-form textarea {
grid-column-end: span 2;
}
.contact-form input[type="submit"] {
grid-column-start: 2;
justify-self: end;
margin-top: 0.6em;
background: #3eb0ef;
color: white;
width: auto;
}
6. Uploading your customized theme with contact form
Next step is to save your theme changes and via the Design view in Ghost admin. To upload a theme to your publication;/content/themes/casper
and zip the whole directory.Improving User Experience
The Getform Thank You Page will be shown to your form submitters by default, but you can change it to one you'd like by .After you finish the setup, based on your needs you can also s, use our to send your form submission data to 100s of other applications and keep your form submissions spam protected by using .BONUS: If you would like to check out the Ghost themes, you can visit the themes section from here: and select your preferred one.
Previously published at //blog.getform.io/how-to-add-a-contact-form-to-your-ghost-blog/