Skip to main content
Forms in OpnForm handle both client-side validation and server-side API integration. They work seamlessly with TanStack Query mutations for optimal user experience.

Form System Overview

Our form system consists of three main parts:
  1. Form Class (client/composables/lib/vForm/Form.js) - Core form state management
  2. useFormInput Composable (client/components/forms/useFormInput.js) - Input component logic
  3. Form Components (client/components/forms/) - Reusable input components

Creating a Basic Form

1. Initialize the Form

The useForm composable creates a reactive form instance with:
  • Data binding - automatic two-way data binding
  • Validation state - tracks errors and validation status
  • Loading state - busy/successful flags for UI feedback
  • Error handling - automatic error extraction from API responses

2. Create the Form Template

3. Handle Form Submission

Form Input Components

Using Form Inputs

All form inputs accept a common set of props through the useFormInput composable:

Available Input Components

  • <TextInput> - Text, email, password, etc.
  • <TextareaInput> - Multi-line text
  • <CheckboxInput> - Checkboxes
  • <SelectInput> - Dropdown selects
  • … and more!

Custom Input Components

Create custom inputs using the useFormInput composable:

Validation & Error Handling

Client-Side Validation

Form validation happens automatically:

Server-Side Validation

The form automatically handles API validation errors:

Precognition (Live Validation)

Use real-time server validation as users type with Laravel Precognition.

Error States

Access validation state programmatically:

Integration with TanStack Query

Forms integrate seamlessly with TanStack Query mutations for optimal caching and state management:
See Data Fetching for more details on how mutations work with caching and optimistic updates.

Form State Management

Form Methods

Form State Properties

Complete Example

Here’s a complete working example based on the LoginForm component:

Best Practices

Form State Management: Always use the useForm composable rather than managing form state manually. It handles validation, errors, and loading states automatically.
Error Handling: Let the form handle API validation errors automatically. Only add custom error handling for specific business logic.
File Uploads: When handling file uploads, the form will automatically serialize data as FormData. Make sure your API endpoint accepts multipart/form-data.
Validation: Combine client-side validation (required, email, etc.) with server-side validation for the best user experience.

Respondent PDF Downloads

When PDF download is enabled and a template is selected for a public form, the completed submission response includes pdf_download_url. The URL is signed for that submission and template and expires after 24 hours. A partial draft, disabled PDF download, or a template outside the form does not receive a download URL. The completion screen uses this URL directly when the respondent clicks Download PDF. It does not call the authenticated template signed-url endpoint, which remains restricted to form administrators. Open the supplied URL synchronously from the click handler to avoid browser popup blocking. Keep the signed URL in the completion screen’s memory and clear it when restarting the form. Treat it as a temporary credential: do not log it or place it in analytics events. Reopening a form with only a submission UUID does not grant a fresh download URL. Administrators can generate a new URL through the authenticated endpoint when needed. Deploy the API response addition and its completion-screen consumer together. An expired link, a failure to generate a PDF, and a missing email notification are separate issues; a successful signed download does not prove email delivery.