Next.js Integration
Next.js Contact Form with only Frontend Code
Start collecting form submissions from your Next.js form with Forms in 2 minutes. Create your form in Forms and paste your unique URL inside your form. Check out the code examples and detailed tutorial below to get started
VS Code
import { useState } from 'react';
export default function FetchForm() {
const [email, setEmail] = useState('');
const [message, setMessage] = useState('');
const [submitted, setSubmitted] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
setError('');
try {
const res = await fetch('https://submit.zunoy.com/sub/[YOUR-FORM-KEY]', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({ email, message }),
});
const data = await res.json();
if (data.code === 200) setSubmitted(true);
else setError(data.message || 'Something went wrong');
} catch (err) {
setError(err.message);
}
};
return (
Email:
setEmail(e.target.value)} required />
Message:
setMessage(e.target.value)} required />
Send
{submitted && Form submitted successfully!
}
{error && {error}
}
);
}How to Integrate Code
What is Next.js?
Next.js is a React framework for building server-side rendered and static web applications. You can use standard React components for forms, and Forms works seamlessly with Next.js frontend.
Forms Setup with Next.js using Fetch
You can use the native Fetch API in Next.js to send form data to Forms. Replace “https://submit.zunoy.com/sub/[YOUR-FORM-KEY]” with your unique mockapi URL.
VS Code
import { useState } from 'react';
export default function FetchForm() {
const [email, setEmail] = useState('');
const [message, setMessage] = useState('');
const [responseText, setResponseText] = useState('');
const submitForm = async () => {
try {
const response = await fetch('https://submit.zunoy.com/sub/[YOUR-FORM-KEY]', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, message }),
});
const data = await response.json();
setResponseText(data.code === 200 ? 'Form submitted successfully!' : 'Error submitting form');
} catch (error) {
setResponseText('Error: ' + error);
}
};
return (
setEmail(e.target.value)} />
setMessage(e.target.value)} />
Submit
{responseText}
);
}Forms Setup with Next.js using Axios
Axios is a simple HTTP client that works in Next.js. You can send form data using Axios and display success or error messages.
VS Code
import { useState } from 'react';
import axios from 'axios';
export default function AxiosForm() {
const [email, setEmail] = useState('');
const [message, setMessage] = useState('');
const [responseText, setResponseText] = useState('');
const submitForm = async () => {
try {
const response = await axios.post('https://submit.zunoy.com/sub/[YOUR-FORM-KEY]', { email, message });
setResponseText(response.data.code === 200 ? 'Form submitted successfully!' : 'Error submitting form');
} catch (error) {
setResponseText('Error: ' + error);
}
};
return (
setEmail(e.target.value)} />
setMessage(e.target.value)} />
Submit
{responseText}
);
}Forms Setup for File Uploads in Next.js
You can upload files using FormData in Next.js with Fetch or Axios. Below is an example using Fetch. Replace the mockapi with your Forms URL.
VS Code
import { useState } from 'react';
export default function FileUploadForm() {
const [file, setFile] = useState(null);
const [responseText, setResponseText] = useState('');
const uploadFile = async () => {
if (!file) return setResponseText('Please select a file');
const formData = new FormData();
formData.append('file', file);
try {
const response = await fetch('https://submit.zunoy.com/sub/[YOUR-FORM-KEY]', {
method: 'POST',
body: formData,
});
const data = await response.json();
setResponseText(data.code === 200 ? 'File uploaded successfully!' : 'Upload failed.');
} catch (error) {
setResponseText('Error: ' + error);
}
};
return (
setFile(e.target.files[0])} />
Upload File
{responseText}
);
}Set Up Forms in 60 Seconds
Create Your Form
Sign up and create a form in Forms — no backend code required.
Get Your Endpoint
Forms gives you a unique endpoint. Point your form's action attribute (or a fetch/axios call) at it.
Start Receiving Submissions
Submissions land instantly in your dashboard inbox, with spam filtering and alerts built in.
USE CASES
Need templates? Say less.
A collection of example HTML forms with code that you can edit live, then download or copy/paste. A minimal form reset css is included that should work with most sites.
Simple Contact Form
Survey Form
Book a Demo Form
News Letter Form
Registration Form & more...
Ready to Experience Zunoy?
Start your journey with Zunoy's powerful suite of tools, designed for startups, developers, and growing teams alike.
All our products come with a lifetime free tier.