Core Documentation

Formgrid Developer Quickstart

Connect any HTML form, vanilla JS fetch handler, React component, or Next.js form to Formgrid.dev in minutes with synthetic examples and proper error handling.

Connect any existing HTML, static-site, React, or Next.js form to a managed endpoint at POST https://formgrid.dev/api/f/{endpointSlug} without writing backend routes.

1. Endpoint URLs and Form Actions

Every form you create in Formgrid gets a unique endpointSlug (for example, your-form-slug). All three public submission paths point to the same handler and support application/x-www-form-urlencoded, multipart/form-data (including file uploads on Premium+), and application/json:

  • Primary recommended URL: https://formgrid.dev/api/f/{endpointSlug}
  • Short alias: https://formgrid.dev/f/{endpointSlug}
  • REST-style alias: https://formgrid.dev/forms/{endpointSlug}/submit

Important: Your endpointSlug is a public form destination for browsers, not a secret API key. Never put a private Management API key (fg_live_...) inside client-side HTML or browser JavaScript.


2. Plain HTML Form (Zero JavaScript)

Add action="https://formgrid.dev/api/f/your-form-slug", method="POST", and name attributes on every input. Include the hidden honeypot field so bots are silently dropped before saving:

<form action="https://formgrid.dev/api/f/your-form-slug" method="POST">
  <label for="name">Name</label>
  <input id="name" name="name" type="text" required placeholder="Jordan Lee" />

  <label for="email">Email</label>
  <input id="email" name="email" type="email" required placeholder="alex@example.com" />

  <label for="message">Project details</label>
  <textarea id="message" name="message" required rows="4"></textarea>

  <!-- Honeypot spam trap: keep hidden from people, do not rename -->
  <input
    type="text"
    name="honeypot"
    tabindex="-1"
    autocomplete="off"
    aria-hidden="true"
    style="position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;"
  />

  <button type="submit">Send enquiry</button>
</form>

HTML Redirect Behavior

When a browser posts a standard HTML form without Accept: application/json, Formgrid responds with an HTTP 302 redirect to:

  1. Your custom redirect URL (available on Premium and Business), or
  2. Formgrid's default hosted confirmation page (/app/success.html).

Using FormData with Accept: application/json keeps your visitor on the page, preserves multipart/form-data compatibility (including file uploads on Premium+), and returns structured JSON:

<form id="contact-form">
  <input name="name" type="text" required placeholder="Jordan Lee" />
  <input name="email" type="email" required placeholder="alex@example.com" />
  <textarea name="message" required placeholder="How can we help?"></textarea>
  <input type="text" name="honeypot" tabindex="-1" autocomplete="off" aria-hidden="true" hidden />
  <button type="submit">Send message</button>
  <p id="form-status" role="status" aria-live="polite"></p>
</form>

<script>
  const form = document.getElementById('contact-form');
  const statusEl = document.getElementById('form-status');
  const submitBtn = form.querySelector('button[type="submit"]');

  form.addEventListener('submit', async (event) => {
    event.preventDefault();
    submitBtn.disabled = true;
    statusEl.textContent = 'Sending...';

    try {
      const response = await fetch('https://formgrid.dev/api/f/your-form-slug', {
        method: 'POST',
        headers: { Accept: 'application/json' },
        body: new FormData(form),
      });

      const payload = await response.json().catch(() => ({}));
      if (!response.ok || payload.success === false) {
        throw new Error(payload.message || `Submission failed (${response.status})`);
      }

      form.reset();
      statusEl.textContent = 'Thanks! Your enquiry has been received.';
    } catch (err) {
      statusEl.textContent =
        err instanceof Error ? err.message : 'Network error. Please try again.';
    } finally {
      submitBtn.disabled = false;
    }
  });
</script>

Why you should never use mode: 'no-cors'

Do not pass mode: 'no-cors' to fetch(). Browser no-cors requests produce an opaque response with status 0, strip Accept: application/json, and prevent your UI from distinguishing a 201 success from a 400 validation error or 403 Allowed Domains block. Formgrid sets CORS headers natively for allowed origins.


4. Sending application/json Payloads

If your frontend or server script submits raw JSON (Content-Type: application/json), wrap your form fields inside the formData object to match Formgrid's validation schema:

const response = await fetch('https://formgrid.dev/api/f/your-form-slug', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Accept: 'application/json',
  },
  body: JSON.stringify({
    formData: {
      name: 'Jordan Lee',
      email: 'alex@example.com',
      message: 'Interested in an estimate for next month.',
    },
    honeypot: '',
  }),
});

Successful JSON Response (201 Created)

{
  "success": true,
  "message": "Form submitted successfully",
  "data": {
    "id": "sub_example_123",
    "status": "new",
    "submittedAt": "2026-11-28T12:00:00.000Z"
  }
}

5. React & Next.js Example (With Loading, HTTP & Network States)

For React and Next.js App Router ('use client') components, submit new FormData(event.currentTarget) to https://formgrid.dev/api/f/your-form-slug and handle all four states explicitly:

'use client';

import { useState, type FormEvent } from 'react';

export function ContactForm() {
  const [status, setStatus] = useState<'idle' | 'submitting' | 'success' | 'error'>('idle');
  const [errorMessage, setErrorMessage] = useState('');

  async function handleSubmit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const form = event.currentTarget;
    setStatus('submitting');
    setErrorMessage('');

    try {
      const response = await fetch('https://formgrid.dev/api/f/your-form-slug', {
        method: 'POST',
        headers: { Accept: 'application/json' },
        body: new FormData(form),
      });

      const data = await response.json().catch(() => ({}));
      if (!response.ok || data.success === false) {
        setStatus('error');
        setErrorMessage(data.message || `Request failed with HTTP ${response.status}`);
        return;
      }

      form.reset();
      setStatus('success');
    } catch {
      setStatus('error');
      setErrorMessage('Unable to reach Formgrid right now. Check your connection and retry.');
    }
  }

  return (
    <form onSubmit={handleSubmit}>
      <input name="name" type="text" required placeholder="Jordan Lee" />
      <input name="email" type="email" required placeholder="alex@example.com" />
      <textarea name="message" required placeholder="Tell us about your project" />
      <input type="text" name="honeypot" tabIndex={-1} autoComplete="off" aria-hidden="true" hidden />
      <button type="submit" disabled={status === 'submitting'}>
        {status === 'submitting' ? 'Sending...' : 'Send message'}
      </button>
      {status === 'success' && <p role="status">Message sent.</p>}
      {status === 'error' && <p role="alert">{errorMessage}</p>}
    </form>
  );
}

6. Allowed Domains (CORS) & Troubleshooting

  • Allowed Domains (403 CORS policy): In Form Settings → Allowed Domains, add every origin that submits via browser fetch (including http://localhost:3000 or http://localhost:5173 while testing locally, plus your production domain).
  • Empty submissions (400 Validation failed): Every field you want stored must have an HTML name attribute and at least one non-empty value.
  • File uploads: Upload fields require Premium ($12/mo monthly or $10/mo billed annually) or Business ($29/mo monthly or $24.17/mo billed annually), up to 1 GB per file.