In today’s digital world, being able to quickly test your ideas and interact with your users is crucial, whether you’re building an MVP, launching a startup, or delivering a project on a tight deadline. Creating a newsletter subscription form is often necessary to validate your concept, engage early users, build a community of interested people, and gather feedback.
Turnkey solutions can be costly, while using free tools is still complex and time-consuming.
In this tutorial, I’ll show you how to create a newsletter subscription form in less than 20 minutes. No complex configurations, no headaches. Just a form with a fully functional subscription system!
Stack Used
- shadcn/UI: ready-to-use, beautifully designed components to build the frontend.
- Manifest: The fastest and easiest way to build a complete backend, just by filling a YAML file.
By the end of this tutorial, you’ll have a fully operational form to collect your first subscribers. Ready? Let’s go!
What is Manifest?
Manifest is our open-source Backend-as-a-Service (BaaS). It allows to create a complete backend for your application.
By simply filling in a single YAML file, you generate a backend with a database, an API, and a user-friendly admin panel for non-technical administrators.
This allows you to focus on building your product instead of dealing with backend complexity.
As of today, we’ve just released our MVP, and we’re counting on community feedback to help us evolve the product in the right direction.
Manifest is available on GitHub, so feel free to give it a ⭐ if you like the project!
Planning the interface
Our goal is a single screen displaying a subscription field and notification messages. It's simple, effective, and functional. Here’s what we’ll get:
- The frontend for subscribers
- The admin panel for the administrators
Creating the frontend with shadcn/UI
We’ll start by creating the project with the frontend, i.e., the visual part of our newsletter subscription form.
I chose to use shadcn/UI with Next.js. Run the following command in your terminal:
npx shadcn@latest init -d
You’ll be prompted to start a new Next.js project and name your project. Answer “Y” and call it newsletter-form.
Once the project is created, you should have your frontend ready, with these files:
Start the development server by running: npm run dev.
Click on the provided link in the terminal. It should open the NextJS welcome screen in your default web browser at https://localhost:3000.
Creating the static form
Let’s create our form by editing app/page.tsx. Since shadcn works with TailwindCSS, we’ll use its classes to build the desired interface. Copy the following code:
export default function Home() { return ( <div classname="w-full lg:grid lg:grid-cols-5 min-h-screen flex sm:items-center sm:justify-center sm:grid"> <div classname="flex items-center justify-center py-12 col-span-2 px-8"> <div classname="mx-auto grid max-w-[540px] gap-6"> <div classname="grid gap-2 text-left"> <h1 id="Subscribe-to-our-Newsletter">Subscribe to our Newsletter! ?</h1> <p classname="text-balance text-muted-foreground"> Get the latest news, updates, and special offers delivered straight to your inbox. </p> </div> <form classname="grid gap-4">{/* Newsletter form here */}</form> </div> </div> <div classname="hidden bg-muted lg:block col-span-3 min-h-screen bg-gradient-to-t from-green-50 via-pink-100 to-purple-100"></div> </div> ); }
You should see a split screen with an area for the form on the left and a gradient space on the right.
Now let’s add the form. It will include the following shadcn components:
- Input
- Button
Install these components via your terminal with the following commands:
npx shadcn@latest add input npx shadcn@latest add button
Then import the components in your page.tsx file like this:
import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input";
Use these two components by adding the following snippet inside the existing
You should have a responsive newsletter form on your frontend. Take a moment to admire your work. And relax, our 20-minute promise is still intact!
Creating the backend with Manifest
Let’s add the backend to store the subscribers and allow administrators to manage them via an admin panel.
Install Manifest at the root of the project with the following command:
npx add-manifest
Once the backend is installed, you should see the following files in your repository:
Now let’s define our data model. Open the backend.yml file and replace the existing code with this one:
name: Newsletter Form entities: Subscriber: properties: - { name: email, type: email }
Run the following command to start your server:
npm run manifest
Once your backend is running, the terminal will provide two links:
- ?️ Admin panel : http://localhost:1111,
- ? API Doc: http://localhost:1111/api.
Launch the admin panel on your browser and log in with the pre-filled credentials. You should now see an empty list of subscribers.
There we have it! In under 3 minutes, We’ve built a full backend for our newsletter subscription form. ?
Connecting Manifest with our frontend
We’ll use Manifest’s SDK to connect the form and add emails directly to the subscribers list from the frontend.
From your project’s root, install the SDK with:
npm i @mnfst/sdk
Let’s add the newsletter subscription functionality to turn the static form into a dynamic one that stores emails using Manifest.
Next.js treats the files in the app directory as Server Components by default. To use interactive features (like React hooks), we need to mark our component as a Client Component.
Add "use client"; at the top of your Home.tsx file:
'use client';
Next, create the handleSubmit function to capture the email and send it to Manifest:
export default function Home() { const handleSubmit = (e: React.FormEvent<htmlformelement>) => { e.preventDefault(); const form = e.currentTarget as HTMLFormElement; const emailInput = form.querySelector('input[name="email"]') as HTMLInputElement; const email = emailInput?.value; if (!email) { alert('Please enter a valid email.'); return; } const manifest = new Manifest(); manifest .from('subscribers') .create({ email }) .then(() => { form.reset(); alert('Successfully subscribed!'); }) .catch((error) => { console.error('Error adding subscriber:', error); alert(`Failed to add subscriber: ${error.message || error}`); }); }; return ( // ... Your existing code here> ); } </htmlformelement>
Now, add the onSubmit={handleSubmit} attribute to your
以上是如何使用 shadcn/UI 和 Manifest 在几分钟内创建新闻通讯注册表单的详细内容。更多信息请关注PHP中文网其他相关文章!

JavaScript核心数据类型在浏览器和Node.js中一致,但处理方式和额外类型有所不同。1)全局对象在浏览器中为window,在Node.js中为global。2)Node.js独有Buffer对象,用于处理二进制数据。3)性能和时间处理在两者间也有差异,需根据环境调整代码。

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python和JavaScript的主要区别在于类型系统和应用场景。1.Python使用动态类型,适合科学计算和数据分析。2.JavaScript采用弱类型,广泛用于前端和全栈开发。两者在异步编程和性能优化上各有优势,选择时应根据项目需求决定。

选择Python还是JavaScript取决于项目类型:1)数据科学和自动化任务选择Python;2)前端和全栈开发选择JavaScript。Python因其在数据处理和自动化方面的强大库而备受青睐,而JavaScript则因其在网页交互和全栈开发中的优势而不可或缺。

Python和JavaScript各有优势,选择取决于项目需求和个人偏好。1.Python易学,语法简洁,适用于数据科学和后端开发,但执行速度较慢。2.JavaScript在前端开发中无处不在,异步编程能力强,Node.js使其适用于全栈开发,但语法可能复杂且易出错。

javascriptisnotbuiltoncorc; saninterpretedlanguagethatrunsonenginesoftenwritteninc.1)javascriptwasdesignedAsalightweight,解释edganguageforwebbrowsers.2)Enginesevolvedfromsimpleterterterpretpreterterterpretertestojitcompilerers,典型地提示。

JavaScript可用于前端和后端开发。前端通过DOM操作增强用户体验,后端通过Node.js处理服务器任务。1.前端示例:改变网页文本内容。2.后端示例:创建Node.js服务器。

选择Python还是JavaScript应基于职业发展、学习曲线和生态系统:1)职业发展:Python适合数据科学和后端开发,JavaScript适合前端和全栈开发。2)学习曲线:Python语法简洁,适合初学者;JavaScript语法灵活。3)生态系统:Python有丰富的科学计算库,JavaScript有强大的前端框架。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Linux新版
SublimeText3 Linux最新版

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中