惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
小众软件
小众软件
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
H
Help Net Security
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
腾讯CDC

Example blog

Ghost routing explained with routes.yaml examples — routes, collections & taxonomies Ghost redirects explained with practical redirects.yaml examples How to Serve JSON or XML Data in Ghost How to Change Your Default Post Template in Ghost Ghost Custom Theme Settings How to add Google Fonts to Ghost Themes How to Configure Ghost with Mailgun Ghost Theme Structure & Organization How to Make Custom Templates in Ghost Themes How to Install Ghost CMS via Ghost-CLI How to Add Syntax Highlighting to Ghost The best Ghost CMS hosting platforms Ghost 6.0 — Social Web and Native Ghost Analytics Ghost CMS Social web beta, email 2FA and more author social links How to keep custom design settings when updating your Ghost theme How to use the public preview card in Ghost How to add members-specific sections in Ghost How to customize the default content CTA in Ghost How to build a custom homepage in Ghost An overview of Ghost editor cards and and how they work Ghost CMS News: One-time payments & collecting sales tax How to customize the private site access template in Ghost How to add custom fonts in Ghost themes Ghost CMS News: Additional payment methods & internal linking How to use Code Injection in Ghost How to set meta data of your custom routes & collections in Ghost Ghost CMS News: TK reminders, ActivityPub and improvements How to format dates and use the date helper in Ghost Ghost CMS internationalization, custom fonts & spam protection Understanding and optimizing post and page settings in Ghost CMS
How to Use the Ghost Subscription Forms in Your Theme & P...
Bright Themes · 2023-09-10 · via Example blog

Subscription forms are an essential part of Ghost, especially with the membership feature, allowing you to grow an email or member list. On self-hosted sites, member and newsletter mail almost always depends on SMTP first—if that is not set up yet, work through configuring Ghost with Mailgun before you tune forms. Most themes ship with subscription forms already; here we focus on how to customize them and how to drop them into posts.

Basic subscription form and options

The most basic sign up form looks like this:

<form data-members-form>
  <input data-members-email type="email" required="true" />
  <button type="submit">Continue</button>
</form>

The data-members-form attribute on the form element, tells Ghost to handle the submit event. The input field for the email is required as well as the submit button.

The data-members-form attribute has 3 possible (optional) values:

  • signin – to send a sign in email to an existing member, if the member doesn't exist a sign up email is sent instead.
  • signup – to send a sign up email to new members. If the provided email is already a member, a sign in email is sent instead.
  • subscribe – to send a subscribe email. If the provided email is already a member, a sign in email is sent instead.

When the submit button is pressed, the form can have different states, which are written to the form class:

  • loading - when the submission is loading
  • success - when the submission was successful
  • error - when the submission ended in error

Create forms for your hbs templates

If you want to create forms in your theme, you will need to edit the template files. You might want to add a subscription form to the sidebar, the footer, or in a popup. The basic form can be used with some additional elements to also provide feedback to the users.

Here is a form for collecting names and email addresses, and also handling error/success messages.

<form class="subscription-form" data-members-form="signup">
  <input data-members-name type="text" placeholder="name" required />
  <input data-members-email type="email" placeholder="email" required />
  <button class="btn" type="submit">Singup</button>
  <div class="success-message">Great! Check your inbox and click the link.</div>
  <div class="error-message">
    Sorry, something went wrong. Please try again.
  </div>
</form>

Of course, some CSS is needed to style this and also make the messages appear when the form class changes. Here is some basic CSS styling for the form, which you can add via Code Injection:

.subscription-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 30rem;
}

.subscription-form input,
.subscription-form button {
  padding: 10px;
  border-radius: 5px;
  box-shadow: none;
  border: 1px solid #cecece;
  margin-bottom: 1em;
}

.subscription-form .success-message,
.subscription-form .error-message {
  display: none;
}

.subscription-form.error .error-message,
.subscription-form.success .success-message {
  display: block;
}

.subscription-box {
  background-color: lightyellow;
  padding: 2em;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border-radius: 5px;
}

As explained earlier, you can change the default behavior of the form to be either subscribe, sign up or sign in.

If you are into hbs you can even create a partial with some parameters such as form_type, button_text, and more to make the form reusable for different purposes.

Member subscription form for your posts

If you don't want to modify your theme, you can still use and implement the form via HTML cards in any post. Go to your Admin and open a post you

This is quite basic, and you might want to add some styling to it. It's a good idea to add a wrapper around the form and with a background color and padding, we can make it more appealing.

<div class="subscription-box">
  <h3>Susbscribe now</h3>
  <form class="subscription-form" data-members-form="signup">
    <input data-members-name type="text" placeholder="name" required />
    <input data-members-email type="email" placeholder="email" required />
    <button class="btn" type="submit">Singup</button>
    <div class="success-message">
      Great! Check your inbox and click the link.
    </div>
    <div class="error-message">
      Sorry, something went wrong. Please try again.
    </div>
  </form>
</div>

Besides the previous CSS code, you can add the following to style the box and how the form is placed inside of it:

.subscription-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2em;
  background-color: palegreen;
  border-radius: 5px;
}

Here is the result (depending on your CSS this might differ):

Ghost CMS subscription form
Ghost CMS subscription form

To make it reusable, you can create a snippet from the HTML card, and simply insert it anywhere you want to in your posts.