Skip to main content
Inertia provides two primary ways to build forms: the <Form> component and the useForm helper. Both integrate with your server-side framework’s validation and handle form submissions without full page reloads.

Form Component

Inertia provides a <Form> component that behaves much like a classic HTML form, but uses Inertia under the hood to avoid full page reloads. This is the simplest way to get started with forms in Inertia.
The component also supports nested data structures, file uploads, and dotted key notation.
You can pass a transform prop to modify the form data before submission. This is useful for injecting additional fields or transforming existing data, although hidden inputs work too.

Wayfinder

When using Wayfinder, you can pass the resulting object directly to the action prop. The Form component will infer the HTTP method and URL from the Wayfinder object.

Default Values

Checkbox Inputs

When working with checkboxes, you may want to add an explicit value attribute such as value="1". Without a value attribute, checked checkboxes will submit as "on", which some server-side validation rules may not recognize as a proper boolean value.

Slot Props

The <Form> component exposes reactive state and helper methods through its default slot, giving you access to form processing state, errors, and utility functions.
The defaults method allows you to update the form’s default values to match the current field values. When called, subsequent reset() calls will restore fields to these new defaults, and the isDirty property will track changes from these updated defaults. Unlike useForm, this method accepts no arguments and always uses all current form values. The errors object uses dotted notation for nested fields, allowing you to display validation messages for complex form structures.

Props and Options

In addition to action and method, the <Form> component accepts several props. Many of them are identical to the options available in Inertia’s visit options.
Some props are intentionally grouped under options instead of being top-level to avoid confusion. For example, only, except, and reset relate to partial reloads, not partial submissions. The general rule: top-level props are for the form submission itself, while options control how Inertia handles the subsequent visit. To style the form while it’s processing, you can target the inert form in the following ways.

Events

The <Form> component emits all the standard visit events for form submissions.

Resetting the Form

The Form component provides several attributes that allow you to reset the form after a submission. resetOnSuccess may be used to reset the form after a successful submission.
resetOnError may be used to reset the form after errors.

Setting New Default Values

The Form component provides the setDefaultsOnSuccess attribute to set the current form values as the new defaults after a successful submission.

Dotted Key Notation

The <Form> component supports dotted key notation for creating nested objects from flat input names. This provides a convenient way to structure form data.
The example above would generate the following data structure.
If you need literal dots in your field names (not as nested object separators), you can escape them using backslashes.
The example above would generate the following data structure.

Programmatic Access

You can access the form’s methods programmatically using refs. This provides an alternative to slot props when you need to trigger form actions from outside the form.
In React and Vue, refs provide access to all form methods and reactive state. In Svelte, refs expose only methods, so reactive state like isDirty and errors should be accessed via slot props instead.

Form Helper

In addition to the <Form> component, Inertia also provides a useForm helper for when you need programmatic control over your form’s data and submission behavior.
To submit the form, you may use the get, post, put, patchand delete methods.
The submit methods support all of the typical visit options, such as preserveState, preserveScroll, and event callbacks, which can be helpful for performing tasks on successful form submissions. For example, you might use the onSuccess callback to reset inputs to their original state.
If you need to modify the form data before it’s sent to the server, you can do so via the transform() method.
You can use the processing property to track if a form is currently being submitted. This can be helpful for preventing double form submissions by disabling the submit button.
If your form is uploading files, the current progress event is available via the progress property, allowing you to easily display the upload progress.

Form Errors

If there are form validation errors, they are available via the errors property. When building Laravel powered Inertia applications, form errors will automatically be populated when your application throws instances of ValidationException, such as when using {'$request->validate()'}.
For a more thorough discussion of form validation and errors, please consult the validation documentation. To determine if a form has any errors, you may use the hasErrors property. To clear form errors, use the clearErrors() method.
If you’re using client-side input validation libraries or do client-side validation manually, you can set your own errors on the form using the setErrors() method.
Unlike an actual form submission, the page’s props remain unchanged when manually setting errors on a form instance. When a form has been successfully submitted, the wasSuccessful property will be true. In addition to this, forms have a recentlySuccessful property, which will be set to true for two seconds after a successful form submission. This property can be utilized to show temporary success messages. You may customize the duration of the recentlySuccessful state by setting the form.recentlySuccessfulDuration option in your application defaults. The default value is 2000 milliseconds.

Resetting the Form

To reset the form’s values back to their default values, you can use the reset() method.
Sometimes, you may want to restore your form fields to their default values and clear any validation errors at the same time. Instead of calling reset() and clearErrors() separately, you can use the resetAndClearErrors() method, which combines both actions into a single call.

Setting New Default Values

If your form’s default values become outdated, you can use the defaults() method to update them. Then, the form will be reset to the correct values the next time the reset() method is invoked.

Form Field Change Tracking

To determine if a form has any changes, you may use the isDirty property.

Canceling Form Submissions

To cancel a form submission, use the cancel() method.

Form Data and History State

To instruct Inertia to store a form’s data and errors in history state, you can provide a unique form key as the first argument when instantiating your form.

Wayfinder

v2.0.6+ When using Wayfinder in conjunction with the form helper, you can simply pass the resulting object directly to the form.submit method. The form helper will infer the HTTP method and URL from the Wayfinder object.

Server-Side Responses

When using Inertia, you don’t typically inspect form responses client-side like you would with traditional XHR/fetch requests. Instead, your server-side route or controller issues a redirect response after processing the form, often redirecting to a success page.
This redirect-based approach works with all form submission methods: the <Form> component, useForm helper, and manual router submissions. It makes handling Inertia forms feel very similar to classic server-side form submissions.

Server-Side Validation

Both the <Form> component and useForm helper automatically handle server-side validation errors. When your server returns validation errors, they’re automatically available in the errors object without any additional configuration. Unlike traditional XHR/fetch requests where you might check for a 422 status code, Inertia handles validation errors as part of its redirect-based flow, just like classic server-side form submissions, but without the full page reload. For a complete guide on validation error handling, including error bags and advanced scenarios, see the validation documentation.

Manual Form Submissions

It’s also possible to submit forms manually using Inertia’s router methods directly, without using the <Form> component or useForm helper:

File Uploads

When making requests or form submissions that include files, Inertia will automatically convert the request data into a FormData object. This works with the <Form> component, useFormhelper, and manual router submissions. For more information on file uploads, including progress tracking, see the file uploads documentation.

XHR / Fetch Submissions

Using Inertia to submit forms works great for the vast majority of situations. However, in the event that you need more control over the form submission, you’re free to make plain XHR or fetch requests instead, using the library of your choice.