The custom form builder system enables creation of dynamic forms with JSON schema validation, conditional field visibility, file upload handling, and comprehensive analytics tracking.
-
Form Schema JSON with Field Types
- Text, Number, Date, File, and Select field types
- Flexible field configuration with validation rules
-
Validators
- Required field validation
- Pattern matching (regex)
- Min/Max value constraints
- File type and size validation
-
Conditional Field Visibility
- Show/hide fields based on other field values
- Field dependencies support
- Complex visibility logic
-
File Upload Handling
- Base64 file encoding
- MIME type validation
- File size limits
- Multiple file type support
-
Form Analytics
- View tracking
- Submission counts
- Completion rates
- Real-time analytics dashboard
-
Auto-Save Drafts
- Browser localStorage integration
- Automatic draft saving
- Draft recovery on page reload
-
Embeddable Forms
- Standalone embed pages via iframe
- CORS-friendly embedding
- Auto-saved form state
Services (services/forms.ts):
- Form CRUD operations
- Schema validation with Zod
- Submission processing
- Draft management
- Analytics calculation
Routes (routes/forms.ts):
GET /api/v1/forms- List all formsPOST /api/v1/forms- Create new formGET /api/v1/forms/:id- Get form by ID (tracks views)PUT /api/v1/forms/:id- Update formDELETE /api/v1/forms/:id- Delete formPOST /api/v1/forms/:id/submissions- Submit formGET /api/v1/forms/:id/submissions- Get submissionsPOST /api/v1/forms/:id/drafts- Save draftGET /api/v1/forms/:id/drafts- Get draftsDELETE /api/v1/forms/:id/drafts/:draftId- Delete draft
Components:
FormBuilder.tsx- Schema builder with drag-drop field orderingFormRenderer.tsx- Dynamic form rendering with validationFormEmbed.tsx- Embeddable form componentFormAnalytics.tsx- Analytics dashboard with chartsFormIframeWrapper.tsx- Iframe embedding instructions
Pages:
dashboard/forms/- Form management hubdashboard/forms/[id]/analytics- Form analytics viewforms/embed/[id]- Embeddable form page
API Methods (lib/api.ts):
api.forms.listForms()
api.forms.getForm(id)
api.forms.createForm(payload)
api.forms.updateForm(id, payload)
api.forms.deleteForm(id)
api.forms.submitForm(id, values)
api.forms.getSubmissions(id)
api.forms.saveDraft(id, values)
api.forms.getDrafts(id)
api.forms.deleteDraft(id, draftId)- Navigate to
/dashboard/forms - Click "Add field" to create form fields
- Configure field type, validation, and conditional visibility
- Click "Save schema"
- Use the embed code or embed URL to integrate the form
Field Types:
- Text: Single-line text input
- Number: Numeric input with min/max constraints
- Date: Date picker
- File: File upload with type/size validation
- Select: Dropdown with predefined options
Validation:
required: Field is mandatorypattern: Regex pattern for text validationmin/max: Min/max values for numbersaccept: File type filter (e.g.,.pdf,.doc)maxSizeBytes: Maximum file size in bytes
Conditional Visibility:
- Set
visibleIfto show field when another field has specific value - Example: Show "Email" field when "Contact Method" = "email"
Via Iframe URL:
<iframe
src="https://your-domain.com/forms/embed/{formId}"
width="100%"
height="600"
frameborder="0"
style="border: 1px solid #e5e7eb; border-radius: 0.5rem;"
></iframe>Copy Code Feature:
- Use the "Embed" button in the forms list to copy the embed URL
- Paste into third-party websites
- Go to
/dashboard/forms - Click "Analytics" button on the form
- View:
- View count
- Submission count
- Completion count
- Completion rate percentage
- Charts showing form activity
- Submission details
- Export submissions as CSV
{
id: string;
name: string;
description?: string;
fields: FormFieldSchema[];
createdAt: string;
updatedAt: string;
analytics: FormAnalytics;
}{
id: string;
name: string;
label: string;
type: 'text' | 'number' | 'date' | 'file' | 'select';
required?: boolean;
placeholder?: string;
helpText?: string;
pattern?: string;
min?: number;
max?: number;
maxSizeBytes?: number;
accept?: string;
options?: FormFieldOption[];
visibleIf?: { fieldName: string; value: string };
}{
id: string;
formId: string;
submittedAt: string;
values: Record<string, unknown>;
success: boolean;
}{
id: string;
formId: string;
values: Record<string, unknown>;
savedAt: string;
}- Large Forms: Virtualized scrolling support with drag-drop reordering
- File Upload Size: Validation with configurable max size limits
- Validation Bypass: Server-side validation ensures data integrity
- Conditional Logic: Proper field visibility tracking during form fill
- Draft Recovery: Automatic restoration from localStorage
- Network Errors: Graceful error handling and retry logic
- CORS: Embeddable forms work cross-domain
{
"name": "Client Intake Form",
"description": "Capture client details and proposal",
"fields": [
{
"id": "field-1",
"name": "clientName",
"label": "Client Name",
"type": "text",
"required": true,
"placeholder": "Enter your full name"
},
{
"id": "field-2",
"name": "projectBudget",
"label": "Project Budget",
"type": "number",
"required": true,
"min": 100,
"max": 100000
},
{
"id": "field-3",
"name": "preferredContact",
"label": "Preferred Contact",
"type": "select",
"required": true,
"options": [
{ "label": "Email", "value": "email" },
{ "label": "Phone", "value": "phone" }
]
},
{
"id": "field-4",
"name": "contactEmail",
"label": "Email",
"type": "text",
"pattern": "^\\S+@\\S+\\.\\S+$",
"visibleIf": { "fieldName": "preferredContact", "value": "email" }
},
{
"id": "field-5",
"name": "proposal",
"label": "Proposal Document",
"type": "file",
"accept": ".pdf,.doc,.docx",
"maxSizeBytes": 5000000
}
]
}- Required field validation
- Pattern matching validation
- Range validation (min/max)
- File type and size validation
- Conditional visibility logic
- Form rendering with all field types
- Draft auto-save functionality
- Submission handling
- Error display
- Analytics tracking
- Input Validation: Both frontend and backend validation
- File Upload: Type and size restrictions
- CORS Support: Safe cross-domain embedding
- Data Persistence: Secure storage in user's browser cache
- Analytics Privacy: Form submissions captured securely
- Lazy Loading: Forms load on demand
- Draft Caching: LocalStorage for instant draft recovery
- Pagination: Submission tables paginated
- Memoization: React memo for form field components
- Debouncing: Draft saving debounced
- Form versioning and rollback
- Template library for common forms
- Advanced conditional logic (AND/OR operators)
- Webhook integration for submissions
- Email notifications on submit
- Multi-step forms/wizards
- Custom CSS styling per form
- Integration with CRM systems
- Form abandonment tracking
- A/B testing capabilities