Using StaticForms with Nuxt.js: A Complete Guide

8 min read
Static Forms Team

Are you building a Nuxt.js application and need a simple way to handle form submissions without setting up a backend server? Static Forms is the perfect solution for collecting form data from your static sites and receiving submissions directly in your inbox.

In this guide, we'll explore how to integrate the StaticForms service with your Nuxt.js application, including both basic implementation and enhanced security with reCAPTCHA. If you're using Next.js instead, check out our Next.js integration guide.

What is StaticForms?

StaticForms is a form-to-email service designed specifically for static websites. It allows you to receive form submissions via email without writing any server-side code. This is particularly useful for:

  • Contact forms
  • Feedback forms
  • Newsletter signups
  • Simple data collection

The service is free to use (with some limitations) and provides a straightforward API for integrating forms into your static website.

Getting Started with StaticForms

Before implementing forms in your Nuxt.js app, you'll need to:

  1. Visit staticforms.dev
  2. Register for a free account
  3. Obtain your unique API key

This API key will be used to connect your forms to your StaticForms account, ensuring submissions are forwarded to your email address.

Basic Integration in Nuxt.js

Let's start by implementing a simple contact form without reCAPTCHA. This approach is quick to set up but offers less protection against spam.

Create a Client-Side Component for Your Form

VUE

Use the Form Component in Your Page

VUE

Enhanced Integration with reCAPTCHA

For better protection against spam and bot submissions, we can add Google reCAPTCHA to our form. First, we need to install the Vue reCAPTCHA package:

Bash

Contact Form with reCAPTCHA

VUE

Using the reCAPTCHA Form Component

VUE

Using Nuxt.js Composition API for Form Reusability

For larger applications, you might want to extract the form logic into a composable function for better reusability:

TypeScript

You can then use this composable in any component:

VUE

Environment Variables in Nuxt.js

For better security, you should store your StaticForms API key as an environment variable:

  1. Add to your nuxt.config.ts:
TypeScript
  1. Create a .env file in your project root:
Plain Text
  1. Access it in your components or composables using useRuntimeConfig:
TypeScript

Conclusion

Integrating StaticForms with Nuxt.js provides a simple, effective solution for handling form submissions in static sites without setting up a backend server. Whether you use the basic implementation or enhance it with reCAPTCHA for extra security, StaticForms makes the process straightforward.

For more information about StaticForms, check out our getting started guide or explore other integration examples for different frameworks, such as our Next.js integration tutorial.

Remember that the free tier has some limitations, but it's perfect for most personal projects and small business websites. For larger projects with higher submission volumes, consider upgrading to a paid plan.

Happy coding with Nuxt.js and StaticForms!