Back to cookbook

AI Prompt to Build a React Multi-Step Form Wizard With Validation

0 views Published

Make this prompt yours

Share

This is an AI prompt for building a React multi-step form wizard: a form split across several steps with a progress indicator, per-step validation, and state that survives moving back and forth between steps. It's built for frontend developers and product teams putting together onboarding flows, checkout processes, signup forms, or any multi-screen data entry flow where dumping everything on one page would overwhelm the user.

The prompt asks the model to define a step configuration structure, a shared form state object, and validation rules that run before a user can advance to the next step — rather than only validating on final submit. It also covers state persistence across steps (so going back doesn't wipe out what was already entered) and a clear way to show progress, since those two details are where most hand-rolled wizards break down.

If you already have a design mockup for the wizard's layout and just need the matching React structure, Site to Prompt can turn a rendered page or screenshot into a build-ready prompt you can merge with the template below.

Prompt template

Make this prompt yours

prompt-template
467 tokens
ROLE: You are a senior frontend engineer who specializes in React form architecture. CONTEXT: - Framework: [REACT VERSION, e.g. React 18 with hooks] - Styling approach: [CSS MODULES / TAILWIND / STYLED-COMPONENTS] - Form library preference: [NONE - PLAIN STATE / REACT HOOK FORM / FORMIK] - Steps needed: [LIST EACH STEP AND ITS FIELDS, e.g. Step 1: Account (email, password). Step 2: Profile (name, company). Step 3: Preferences (plan, notifications)] - Validation rules: [LIST RULES PER FIELD, e.g. email must be valid format, password min 8 characters] TASK: Build a multi-step form wizard component with the following requirements: 1. A shared state object holding data from all steps, so navigating back and forth never loses entered values 2. Per-step validation that blocks the "Next" button until the current step's required fields are valid, with inline error messages 3. A progress indicator showing the current step out of the total number of steps 4. Back and Next navigation, with Back always enabled (except on step 1) and Next disabled until validation passes 5. A final review step before submission showing a summary of all entered data, with the ability to jump back to any step to edit it 6. A loading/submitting state on final submit that disables the submit button to prevent double submission 7. Clear separation between step configuration (data) and the rendering logic, so adding or removing a step does not require rewriting the component CONSTRAINTS: - [SPECIFY ACCESSIBILITY REQUIREMENTS, e.g. keyboard navigable, ARIA labels on progress indicator] - [SPECIFY WHETHER STATE SHOULD PERSIST ACROSS PAGE REFRESH, e.g. using localStorage or session state] - [SPECIFY IF STEPS ARE CONDITIONAL, e.g. step 3 only appears if plan = enterprise] OUTPUT FORMAT: Provide the complete component code, broken into logical files or sections (step config, main wizard component, individual step components, validation logic). Add brief comments explaining the state flow between steps. After the code, list any assumptions made about fields or behavior that were not specified above.

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
266 tokens
ROLE: You are a senior frontend engineer who specializes in React form architecture. CONTEXT: - Framework: React 18 with hooks - Styling approach: Tailwind CSS - Form library preference: none, plain React state - Steps needed: Step 1: Account (email, password, confirm password). Step 2: Business Info (company name, industry, team size). Step 3: Plan Selection (plan tier, billing cycle) - Validation rules: email must match a valid email pattern, password minimum 8 characters with at least one number, confirm password must match password, company name required, team size must be a positive number TASK: Build a multi-step form wizard component with shared state across steps, per-step validation blocking Next until valid, a progress indicator, Back/Next navigation, a final review step with edit links back to each step, a submitting state that disables the button during submission, and configuration-driven steps. CONSTRAINTS: - Must be keyboard navigable with ARIA labels on the progress indicator - Persist form state in sessionStorage so a refresh does not lose progress - No conditional steps needed OUTPUT FORMAT: Complete component code split into step config, main wizard component, step components, and validation logic, with brief comments on state flow. List assumptions after the code.

When to use it

  • Building a signup or onboarding flow that collects account, profile, and preference data across separate screens
  • Building an e-commerce checkout with shipping, payment, and review steps
  • Replacing a single giant form that users are abandoning partway through
  • Prototyping a survey or intake form where later steps depend on earlier answers

Best practices

  • Validate each step before allowing the "Next" button to advance, not only at final submit
  • Keep all step data in one shared state object so going back and forth never loses entries
  • Show a visible progress indicator (step count or progress bar) so users know how much is left
  • Run the finished prompt through Prompt Debugger first to catch missing edge cases, like what happens if a user refreshes mid-wizard

Common mistakes

  • Only validating on final submit, so users reach step 5 before learning step 1 had an error
  • Resetting form state when a user clicks back, forcing them to re-enter everything
  • Hardcoding step order instead of defining steps as data, which makes reordering or conditional steps painful later
  • Skipping a loading or submitting state on the final step, letting users double-submit by clicking twice

FAQs

How do I keep form data from being lost when a user clicks back in a multi-step form?

Store all step data in one shared state object at the wizard's top level instead of inside each step component, and update that single object as the user moves between steps. Optionally persist it to sessionStorage or localStorage so it also survives an accidental page refresh.

Should I validate each step or only validate when the user submits the whole form?

Validate each step before allowing the user to advance to the next one. Waiting until final submit means a user can fill out five steps only to discover an error on step one, which is a common reason multi-step forms get abandoned.

Can ChatGPT or Claude generate the full multi-step wizard in one response?

Both can generate a complete working wizard in one response if the prompt specifies the steps, fields, and validation rules clearly enough, though for a form with many steps or complex conditional logic you may need a follow-up prompt to fill in individual step components the model summarized or abbreviated.

What's the best way to show progress in a multi-step form?

A simple "Step X of Y" label with an ARIA progressbar role works for accessibility and is easy to implement; a visual progress bar or numbered step indicator on top of that improves the experience for sighted users but isn't required for the wizard to function correctly.

Which Cuelara tool can help me strengthen this prompt before using it?

Prompt Debugger — it scans a prompt like this one for missed edge cases, such as what happens on page refresh or double-submission, before you run it against a model. Site to Prompt — if you already have a design mockup of the wizard, it converts the rendered layout into a prompt you can combine with the template above.

Found this prompt useful? Share it.

Share

More in React Prompt Recipes

React Prompt Recipes

AI Prompt to Build a React Billing Dashboard Component Using Stripe's MCP Server

This prompt is for frontend developers who need to build a React billing dashboard component that shows a customer's live subscription, invo…

ROLE:
You are a senior React/TypeScript developer building a billing dashboard component for a SaaS product.

CONTEXT:
The component should display billing data for a customer, retrieved via Stripe's MCP server: [LIST_DATA_NEEDED_E.G._SUBSCRIPTION_PLAN_NEXT_CHARGE_DATE_PAYMENT_METHOD_RECENT_INVOICES]
Framework/styling: [REACT_VERSION_AND_STYLING_APPROACH_E.G._TAILWIND_CSS_MODULES]

CONSTRAINTS:
- Handle these billing states explicitly: [LIST_STATES_E.G._ACTIVE_PAST_DUE_CANCELED_PENDING_NO_PAYMENT_METHOD]
- Show a loading skeleton while data is being fetched, and a clear error state if the fetch fails
- Format currency and dates using the customer's actual locale/currency, not a hardcoded format
- Separate the data-fetching hook from the presentational component

OUTPUT FORMAT:
1. A short explanation of the component's structure (hook + presentational component)
2. The full TypeScript code, in a single fenced code block, with comments marking where each billing state is handled
3. A one-line note on any assumption you made about the data shape returned by the MCP server

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Dark Mode Toggle with System Preference Detection

A React dark mode toggle prompt asks ChatGPT, Claude, or Gemini to generate a theme switching component that respects the user's OS level li…

Role: You are a senior React developer building a reusable UI component.

Context:
Framework/setup: [REACT VERSION, e.g. React 18 with Vite, Next.js App Router]
Styling approach: [CSS variables / Tailwind CSS dark class / CSS-in-JS library]
Component location/usage: [where the toggle will live, e.g. app header, settings page]

Task:
Build a dark mode toggle component with this exact behavior:
1. On first load, detect the user's OS preference via the `prefers-color-scheme` media query and use it as the initial theme, applied before the main content paints (no flash of the wrong theme).
2. If the user has previously made an explicit choice, that stored choice overrides the OS preference on future visits.
3. Persist the user's explicit choice in [STORAGE MECHANISM, e.g. localStorage].
4. Listen for theme changes made in other open tabs and update this tab's theme to match.
5. Expose the current theme and a toggle function via [CONTEXT/HOOK NAME, e.g. a useTheme hook] so other components can read and react to it.

Constraints:
- Use [STYLING APPROACH] to apply the theme, not inline style objects
- Include accessible labeling (aria-label or visible text) that reflects the current state
- Keep the component dependency-free unless [ALLOWED LIBRARIES] are specified

Output format:
Return the full component code in a fenced code block, followed by a short usage example showing how to wrap the app and consume the hook elsewhere.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Kanban Board With Drag-and-Drop

This prompt gives ChatGPT, Claude, or Gemini a complete specification for building a React Kanban board with drag and drop column reordering…

You are a senior React developer specializing in accessible, production-ready UI components.

Context:
- Framework: [REACT VERSION, e.g. React 18 with TypeScript]
- Drag-and-drop library: [LIBRARY NAME, e.g. @dnd-kit/core]
- Styling approach: [e.g. Tailwind CSS, CSS Modules, styled-components]
- Columns or workflow stages: [LIST OF COLUMN NAMES, e.g. Backlog, In Progress, Review, Done]
- State source: [e.g. local state, Zustand store, REST API endpoint]

Build a Kanban board component with the following requirements:
1. Render one column per workflow stage listed above, each showing its card count
2. Support dragging cards between columns and reordering cards within a column
3. Support keyboard-based reordering, not mouse-only interaction, for accessibility
4. Identify cards by a stable [ID FIELD NAME] field, never by array index
5. Call a [CALLBACK NAME] function on every successful move, passing the card id, source column, destination column, and new index
6. Show an optimistic UI update immediately, then roll back if [CALLBACK NAME] rejects
7. Handle empty columns and drops outside any valid column gracefully

Output format:
- The main board component
- Column and Card subcomponents
- Any custom hooks used for drag state
- A short usage example showing how to wire [CALLBACK NAME] to a real API call
- Brief notes on any library-specific setup required, such as providers, context, or CSS imports

Make this prompt yours