<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.
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 theaction 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 explicitvalue 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.
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 toaction and method, the <Form> component accepts several props. Many of them are identical to the options available in Inertia’s visit options.
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
TheForm 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
TheForm 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.
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.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.
get, post, put, patchand delete methods.
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.
transform() method.
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.
progress property, allowing you to easily display the upload progress.
Form Errors
If there are form validation errors, they are available via theerrors 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()'}.
hasErrors property. To clear form errors, use the clearErrors() method.
setErrors() method.
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 thereset() method.
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 thedefaults() 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 theisDirty property.
Canceling Form Submissions
To cancel a form submission, use thecancel() 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 theform.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.<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’srouter 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 aFormData 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 orfetch requests instead, using the library of your choice.