shadcn.io is not affiliated with official shadcn/ui
Form examples · Patterns
Contact Form for React
A contact form with name, email, a subject select and a message textarea under a Get in touch heading.
The form behind every Contact us page: name, email, a subject to route the request and a message. The Input, Select and Textarea each sit in a Field with its FieldLabel and FieldError, wired to React Hook Form by a Controller, and a Zod schema checks all four before Send Message submits. Use it for support requests, sales inquiries or feedback.
Preview
Installation
FAQ
What does each contact field check?
name is .min(2) with "Name must be at least 2 characters.", email is z.email("Please enter a valid email address."), and message is .min(10) with "Message must be at least 10 characters."
What shows if subject is left unset?
subject starts as "" and must pass .min(1, "Please select a subject."), so Send Message without one marks the field invalid and shows that message. Until then the trigger shows "Select a subject".
How is the subject select wired?
The options are General Inquiry, Technical Support, Sales, Feedback and Other, stored as general, support, sales, feedback and other. Select takes items, value={field.value || null}, and onValueChange stores the next value or "".
How is the message textarea set up?
The Textarea has rows={5}, resize-none and the placeholder "How can we help you?", with the FieldDescription "Please provide as much detail as possible."
Related
- Form with Mixed ControlsA support request form that mixes a text
- Form with SelectA required country select with a
- Login FormA login form with a welcome heading
- Simple TextareaA plain textarea with a placeholder and
- Vertical Layout (Default) FormA form with labels above their inputs and
- Checkout FormA checkout form with a contact email