Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Form examples · Multi Field

Long Form with Many Fields for React

A nine-field registration form in three sections, Account Details, Personal Information and Address, with a full-width submit button.

Framework
UI library

Registration forms with nine or more fields feel intimidating without structure. This one sorts username, email, names, phone and a full address into three FieldSets with a FieldLegend each, using two- and three-column grids where fields pair up. Every field is a Field with its FieldLabel, Input and FieldError, wired to React Hook Form by a Controller and checked by one Zod schema. Use it for full registration, checkout or profile setup.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How are the nine fields grouped?

Three FieldSets, each with a FieldLegend and a FieldGroup: Account Details (username, email), Personal Information (first name, last name, phone) and Address (street, then city, state and ZIP). The form is w-full max-w-md.

Which rows are grids?

First and last name share a grid grid-cols-2 gap-4 row. City, State and ZIP share a grid grid-cols-3 gap-4 row. Every other field spans the width.

What does the schema check, with no custom messages?

Username needs 3 characters; first name, last name, street, city and state need 2; email is z.email(); phone and ZIP match patterns. None sets a message, so the errors are Zod's defaults.

What do the phone and ZIP patterns accept?

PHONE_PATTERN is ^\+?[1-9]\d{1,14}$: an optional plus, then 2 to 15 digits with no spaces or punctuation. ZIP_CODE_PATTERN is ^\d{5}(-\d{4})?$, such as 10001 or 10001-1234.

Which inputs set a type?

Email is type="email" and phone is type="tel"; the rest are text inputs. Each label's htmlFor matches its input's id, such as long-form-with-many-fields-zip-code.

What does Complete Registration receive?

It's a full-width type="submit" button. form.handleSubmit(onSubmit) logs all nine values to the console once the schema passes.