cnippet/ui
  1. ui
  2. forms
  3. form

forms

Form

A form wrapper component that simplifies validation and submission. Built with Base UI and Tailwind CSS. Copy-paste ready.

API Reference

Installation

Usage

Anatomy

Good to know

  • onFormSubmit(values) receives an object keyed by each Field's name, and it calls preventDefault() for you. The native onSubmit still works if you need the raw event.
  • Every Field needs a name, or its value won't appear in values.
  • Show server-side errors by passing errors, an object keyed by field name, e.g. { email: "Already taken" }. They appear in each field's FieldError.
  • Fields validate on submit by default, then again on each change. Set validationMode="onBlur" or "onChange" on the Form to change it for every field.
  • Button defaults to type="button", so the submit button needs type="submit".
  • To use React Hook Form, TanStack Form or server actions, see the Forms guide.

API Reference

Form

Styled wrapper around Base UI's Form primitive. Renders a <form> element and provides shared validation context to all Field children.

Accepts all standard <form> HTML attributes. Key props:

Examples

Using with Zod

Integrates the Form component with a Zod schema for type-safe client-side validation, showing inline field errors on submit.

Sign In

Email and password fields with a show/hide visibility toggle, a "Forgot password?" link, a "Remember me" checkbox, and a "Create account" fallback.

Profile Settings

A card-wrapped profile editor with first and last name, username (with field description), role select, bio textarea with character hint, and website URL. The save button shows "Saved!" for three seconds after submission.

Contact Form

Name grid, email, topic select, priority radio group, and message textarea. On submit, the form is replaced with a success confirmation state.

Change Password

A card-wrapped form with current password, then new and confirm password fields separated by a divider. Client-side validation checks minimum length and that both new fields match.

Newsletter Signup

A centered card with a mail icon, first/last name grid, email, a "weekly digest" checkbox pre-checked, and a subscribe button. Confirming shows a success state with the submitted email address echoed back.

Multi-step Onboarding

A three-step wizard with a numbered step indicator: step 1 collects name and email, step 2 presents a plan radio group and newsletter preference, step 3 shows a read-only summary before final account creation.

Sign Up

Email, password, and confirm-password fields with a terms checkbox. A minimal register form for new accounts.

Feedback

A rating select paired with a free-text textarea. On submit, the form is replaced with a thank-you confirmation.

Forgot Password

Email input that triggers a reset link. On success, the form swaps to a confirmation card echoing the submitted address with a resend option.

Delete Account

A danger zone confirmation form with a highlighted warning, requiring the user to type a specific phrase before the destructive submit button becomes active.

Invite Team Member

Email address and role select for adding a workspace collaborator, with a role description and cancel/invite action buttons.