GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Forms

Write the schema of a form. ViteHub checks each message, stores it, emails you, and shows it in the Console.

Deploys on
  • Node
  • Docker
  • Cloudflare
  • Vercel
  • Netlify
shared/schemas.ts
import * as v from 'valibot'

export const ContactSchema = v.object({
  email: v.pipe(v.string(), v.email()),
  message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(5000)),
})
shared/schemas.ts
PartWhat it does
GuardAccepts only POST, rejects a present Origin unless it is your origin or in origins, blocks large bodies, answers a filled honeypot field with a fake success, and limits each address to 5 messages a minute. Requests without Origin may pass.
ValidationChecks each message with your Standard Schema: Valibot, Zod, or ArkType. A bad message gets the error of each field.
InboxKeeps each message in the vitehub_form_submissions table, with its page and the sentence the sender selected. The Console lists them.
NotifyEmails each message to you through Email, with reply-to set to the sender.
onSubmitRuns your code before Forms stores the message, for example to post it to a support tool.

Use Comments when readers talk with each other on the page. Use Forms when messages stay private and go straight to you.

  • Get started: add a contact form to a ViteHub app.
  • Server API: every option of defineForm() and the inbox.
  • Vue: AutoForm, useFormAction(), and useFormSubmit() for Formisch.