Forms

Dynamic form system (Form Builder v3) for creating, configuring, and submitting forms. Admins design forms with conditional logic and field triggers; customers fill them via the Portal; submissions are stored and reviewed internally.

Source Files

LayerPath
Schemabackend/src/db/schema.ts
Form Routesbackend/src/routes/admin/forms/
Field Routesbackend/src/routes/admin/form-fields/
Submission Routesbackend/src/routes/form-submissions.ts
Builder Pagefrontend/src/pages/admin/FormBuilder.tsx
Forms Adminfrontend/src/pages/admin/FormsAdmin.tsx
Fields Adminfrontend/src/pages/admin/FormFieldsAdmin.tsx
Componentsfrontend/src/components/form-builder/ (29 files)
Contextfrontend/src/contexts/FormBuilderContext.tsx

Database Tables

TablePurpose
formsMain entity — name, description, status, version
formFieldDefinitionsReusable field definitions (type, validation rules, options)
formFieldSectionsLogical groupings of fields within a form
formToFormFieldsM2M linking forms to field definitions with ordering and config
formToSectionsM2M linking forms to sections with ordering
formSubmissionsCompleted form submissions with response data

Form Builder Architecture

The Form Builder v3 uses a drag-and-drop editor with three panels:

PanelComponentPurpose
SidebarFormBuilderSidebarField palette and section list
EditorFormBuilderEditorCanvas for arranging fields and sections
ConfigFieldConfigPanelProperties, validation, and conditions for selected field
PreviewFormBuilderPreviewLive preview of the form as customers see it

State is managed via FormBuilderContext — a React context holding the current form structure, selection state, and undo history.

Key Features

  • Conditional visibility — fields can be shown/hidden based on other field values via a condition editor
  • Trigger system — field interactions can trigger side effects (e.g., auto-fill, show warning)
  • Field types — text, number, date, select, multi-select, file upload, checkbox, radio, rich text, signature
  • Sections — fields are grouped into collapsible sections for organization
  • Reusable fieldsformFieldDefinitions can be shared across multiple forms
  • Submissions — responses stored in formSubmissions, viewable in admin

Frontend Components

ComponentPurpose
FormRendererRenders a form for end-user filling (used in Portal)
ConditionEditorVisual editor for field visibility conditions
TriggerEditorConfigure field interaction triggers
FieldTypeSelectorPicker for available field types
SectionManagerAdd, reorder, and configure sections
FormPreviewDialogFull-screen preview of the form

Relationships

Form 1──* FormToFormFields ──* FormFieldDefinitions
Form 1──* FormToSections ──* FormFieldSections
Form 1──* FormSubmissions
FormSubmission *──1 Users (submitter)
FormSubmission *──* Files (uploaded attachments)

Integration Points

  • Document Obtaining — forms define what information customers must provide for specific document types
  • PortalFormRenderer is the primary way customers interact with forms
  • Files — file upload fields store attachments via the file system
  • Validation Pattern — form field validation uses Zod schemas generated from field definitions

Form Builder | Document Obtaining | Portal | Files | Validation Pattern | Admin Dashboard | Service Layer Pattern | React Query Pattern