Sub topic 12
The review step and final submission
This chapter assumes you can build a basic form, know how the state machine from the earlier chapters works (steps, values, errors), and have seen how drafts are saved. Here we cover the last step before data leaves the browser: the review step, and the final submission that follows it.
Why a review step exists
A review step shows every answer the user entered, grouped by step, before anything is sent. It has three jobs:
- It lets the user catch mistakes that passed validation. An email can be well formed and still be the wrong address.
- It gives the user a sense of control. Sending is a deliberate act, not a side effect of pressing Enter.
- It gives you one place to run a final check across all steps.
Not every flow needs one. A short two-step newsletter signup can skip it. Add a review step when the data is costly to correct later: payments, applications, legal declarations, orders that ship physical goods.
What the review step shows
Show a summary, not a second copy of the form. Each section carries a heading that matches the step name, the answers as label and value pairs, and a "Change" link that returns to that step.
A good summary follows these rules:
- Use the same labels the user saw in the form, so nothing needs translating.
- Show only fields that are currently visible. Answers from a hidden branch must not appear here, and must not be submitted (see the conditional fields chapter).
- Show "Not provided" for optional fields left empty, so the user can tell a blank answer from a missing row.
- Mask sensitive values. Show a card number as "ending in 4242", not in full.
- Make the "Change" link name its target. A screen reader user hears a list of identical "Change" links otherwise. Use text like "Change email address" or add visually hidden text.
<section aria-labelledby="review-account">
<h2 id="review-account">Account</h2>
<dl>
<dt>Email address</dt>
<dd>[email protected]</dd>
</dl>
<a href="#account">Change<span class="visually-hidden"> account details</span></a>
</section>A description list (dl, dt, dd) is the right element for label and value pairs. Assistive technology announces it as a list of terms and definitions.
Editing from the review step
When the user clicks "Change", send them to that step and bring them back to the review step afterward. Without this, a one-word fix forces them to click "Next" through every later step.
Add a returnTo field to the state. When the user chooses "Change", set returnTo to "review". When they finish the step, the "Next" action goes to returnTo instead of the next step in order.
const steps = ["account", "details", "review"] as const;
type StepId = (typeof steps)[number];
type State = {
step: StepId;
values: Record<string, string>;
errors: Record<string, string>;
returnTo: StepId | null;
};
type Action =
| { type: "edit"; step: StepId }
| { type: "next" };
function validate(step: StepId, values: Record<string, string>): Record<string, string> {
const errors: Record<string, string> = {};
if (step === "account" && !values.email?.includes("@")) {
errors.email = "Enter an email address in the format [email protected].";
}
if (step === "details" && !values.name?.trim()) {
errors.name = "Enter your full name.";
}
return errors;
}
function reducer(state: State, action: Action): State {
switch (action.type) {
case "edit":
return { ...state, step: action.step, returnTo: "review", errors: {} };
case "next": {
const errors = validate(state.step, state.values);
if (Object.keys(errors).length > 0) return { ...state, errors };
if (state.returnTo) {
return { ...state, step: state.returnTo, returnTo: null, errors: {} };
}
const index = steps.indexOf(state.step);
return { ...state, step: steps[Math.min(index + 1, steps.length - 1)], errors: {} };
}
}
}There is one edge case. A changed answer can switch a conditional branch on, which adds a required field the user has never seen. If the user changes "delivery" from "pickup" to "ship", the address field becomes visible and empty. Returning straight to the review step would skip it. The fix is to run the full validation on every visible field when the user returns to review, and send them to the first step with an error instead.
Validating the whole flow before submitting
Per-step validation protects the user's progress. It does not guarantee the complete data set is valid, because:
- The user may have jumped back and changed an earlier answer that affects a later one.
- A saved draft may have been created under older rules.
- Browser autofill or scripts may have changed values without triggering your checks.
So validate every step again when the review step loads, and again when the user submits. Run the same validate function for each step against the active values.
type Values = Record<string, string>;
function validateAll(
stepIds: readonly string[],
values: Values,
validateStep: (step: string, values: Values) => Record<string, string>
): { step: string; errors: Record<string, string> } | null {
for (const step of stepIds) {
const errors = validateStep(step, values);
if (Object.keys(errors).length > 0) return { step, errors };
}
return null;
}If the function returns a result, move the user to that step and show the errors. Say why: "We need one more detail before you can submit. Enter your full name." A silent redirect looks like a bug.
The browser check is a convenience. The server must validate again, because anyone can send a request without using your form. Treat client validation as feedback and server validation as the rule.
Building the payload
Do not send the raw state object. Build the payload from the active values only, using the activeValues approach from the conditional fields chapter. Then map names and types to what the API expects: trim strings, convert number strings to numbers, and drop UI-only keys such as returnTo.
type Field = {
name: string;
visibleWhen?: (values: Record<string, string>) => boolean;
};
function buildPayload(fields: Field[], values: Record<string, string>) {
const payload: Record<string, string> = {};
for (const field of fields) {
const visible = !field.visibleWhen || field.visibleWhen(values);
if (visible && field.name in values) {
payload[field.name] = values[field.name].trim();
}
}
return payload;
}The payload that you validate, the payload that the review step displays, and the payload that you send should come from the same function. If the three drift apart, the user confirms one thing and submits another.
The submit button and its states
The final button should say what it does: "Place order", "Submit application", "Send request". "Submit" and "Finish" are weak labels, and "Next" is wrong because nothing follows.
While the request is in flight, the form is in a submitting state. In that state:
- Disable the button, or ignore further clicks, so the user cannot send twice.
- Change the label to "Placing order…" so the user knows something is happening.
- Keep the form data on screen. Do not clear anything until the server confirms success.
- Announce the status to screen readers with an element that has
role="status".
Prefer ignoring clicks in code over relying on the disabled attribute alone. A disabled button drops out of keyboard focus, so a keyboard user can lose their place. Setting aria-disabled="true" and guarding the handler keeps focus where it was.
let submitting = false;
async function onSubmit(send: () => Promise<Response>): Promise<void> {
if (submitting) return;
submitting = true;
try {
const response = await send();
if (!response.ok) throw new Error(`Request failed with status ${response.status}`);
} finally {
submitting = false;
}
}Lifecycle of a submission
The whole review and submit sequence is a small state machine of its own. Naming its states makes the edge cases easier to reason about.
Failed submissions, retries, and duplicate prevention are covered in the next chapter. For now, one rule matters: a failure must return the user to a screen that still holds all their answers.
After success
When the server accepts the data:
- Clear the saved draft, so a later visit does not offer to resume a flow that is already complete.
- Show a confirmation that states what happened and what comes next: "Your order is placed. A receipt is on its way to [email protected]."
- Move keyboard focus to the confirmation heading, so screen reader users hear it.
- Give the user something to keep, such as a reference number, and a clear next action.
- Make the Back button safe. If the user presses it, they should not land on a live, editable form that resubmits an old order. Redirect to a confirmation page or show the completed state.
const DRAFT_KEY = "signup-draft";
function finishFlow(confirmationHeading: HTMLElement): void {
sessionStorage.removeItem(DRAFT_KEY);
confirmationHeading.setAttribute("tabindex", "-1");
confirmationHeading.focus();
}Common errors
| Mistake | What goes wrong | Fix |
|---|---|---|
| Review step lists hidden fields | The user sees answers they never meant to give | Build the summary from active values only |
| "Change" returns to step 1 and forces a click-through | Small fixes feel expensive | Use `returnTo` to come back to review |
| No full re-validation on submit | A stale draft or a changed branch sends invalid data | Validate every step, then validate on the server |
| Payload built separately from the summary | The user confirms one thing and sends another | Use one function for both |
| Form cleared while the request is pending | A failure loses the user's work | Clear only after a confirmed success |
| Generic "Submit" button | The user is unsure what happens next | Use a specific verb and object |
| Focus is lost after submit | Screen reader users hear nothing | Move focus to the confirmation or the first error |
| Draft not cleared after success | The user is offered an old, finished flow | Remove the draft on success |
Exercises
Exercise
A user on the review step clicks "Change" next to their delivery method, switches from "pickup" to "ship", and clicks "Next". Your flow sends them straight back to review. What can go wrong, and how do you prevent it?
Show answer
Switching to "ship" makes the address field visible, and it is still empty. Returning directly to review skips it, so the user could submit an incomplete order. Prevent this by validating every visible field when returning to review (or on submit) and sending the user to the first step with an error, with a message explaining what is missing. The server must also reject the incomplete order.
Exercise
Why should the summary, the validation, and the submitted payload all be built from the same active-values function?
Show answer
If they are built separately, they can disagree. The summary might show a hidden field that is not submitted, or the payload might include a stale answer from a hidden branch that the user never saw. One shared function guarantees that what the user confirms is exactly what is validated and sent.
Exercise
Give two reasons to keep the user's answers on screen and in state while a submission is in flight, and name the point at which you may clear them.
Show answer
First, the request can fail or time out, and the user needs their answers to retry without retyping. Second, the user may go back to edit after a failure. Clear the data and the saved draft only after the server confirms success, such as with a 2xx response.