360 Secure SkillHub
360 安全技能中心

Form Validation

核心功能是提供6阶段专业表单验证全流程方案,涵盖模型schema统一、规则分层、UX时机选择、可访问性优化、异步与服务端验证对齐及测试环节,支持前后端schema共享,处理API错误映射等问题。典型场景包括长表单、多步骤向导/结账、可访问性审计问题、客户端与服务端验证不匹配等。需先确认使用的表单框架,输出完整流程方案及验收清单,减少验证bug,提升表单UX与可访问性。

mike47512
mike47512
热度 51.51
最近更新 2026-05-11 17:36:11
分类:开发依赖:纯提示词应用场景:调试排错 / API 集成 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add form-validation
Metadata
name
form-validation
description
Deep form validation workflow—schemas, sync vs async rules, UX patterns, accessibility, and server parity. Use when building complex forms, multi-step wizards, or reducing validation bugs.

Form Validation

Validation combines correctness and UX: when errors appear, how they are announced, and how client rules match the server.

When to Offer This Workflow

Trigger conditions:

  • Long forms, wizards, or multi-step checkouts
  • Accessibility audits flagging unclear errors
  • Mismatch between client-side “valid” and API rejection

Initial offer:

Use six stages: (1) model & schema, (2) rule layers, (3) UX timing, (4) accessibility, (5) async & server parity, (6) testing). Confirm framework (React Hook Form, Formik, native, etc.).


Stage 1: Model & Schema

Goal: Single schema (Zod, Yup, JSON Schema) as source of truth; share with backend when feasible.


Stage 2: Rule Layers

Goal: Separate required/format rules from cross-field rules (e.g., date range); isolate async checks (username available) from fast inline validation.


Stage 3: UX Timing

Goal: Choose onBlur vs onSubmit per field; avoid shouting on every keystroke unless real-time feedback is a product requirement.


Stage 4: Accessibility

Goal: Associate errors with fields via aria-describedby; move focus to first error on submit; use live regions judiciously.


Stage 5: Async & Server Parity

Goal: Map API validation errors to fields; handle race conditions on slow networks; idempotent submit with dedupe if needed.


Stage 6: Testing

Goal: Unit-test schema; e2e critical paths including server error mapping.


Final Review Checklist

  • Schema aligned or shared with server
  • Validation timing and copy defined
  • Accessible error patterns
  • API errors mapped to UI
  • Tests for schema and flows

Tips for Effective Guidance

  • Server rules always win—document intentional client shortcuts.
  • Pair with ux-writing for error microcopy.

Handling Deviations

  • Wizards: validate per step and on final submit; persist drafts securely.