Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.formbase.dev/llms.txt

Use this file to discover all available pages before exploring further.

React Hook Form gives you structured values and validation hooks. You can submit those values directly to Formbase as JSON, or switch to FormData when you need file uploads. These examples use client-side fetch. If you prefer a JSON response from Formbase, submit from a server action or API route.
1

Create your form

Register fields as usual with useForm.
2

Submit to Formbase

import { useForm } from 'react-hook-form';

type FormValues = {
  name: string;
  email: string;
  message: string;
};

export default function ContactForm() {
  const { register, handleSubmit, formState: { isSubmitting } } = useForm<FormValues>();

  const onSubmit = async (data: FormValues) => {
    const response = await fetch('https://formbase.dev/s/YOUR_FORM_ID', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(data),
      redirect: 'manual',
    });

    if (response.status !== 303 && !response.ok) {
      throw new Error('Submission failed');
    }
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register('name')} placeholder="Name" required />
      <input {...register('email')} type="email" placeholder="Email" required />
      <textarea {...register('message')} required />
      <button type="submit" disabled={isSubmitting}>
        {isSubmitting ? 'Sending...' : 'Send'}
      </button>
    </form>
  );
}
JSON is great when you want structured data or arrays.
Client submissions get a 303 redirect response. Treat 303 as success or submit from a server action for JSON.