Submitting Forms
While it’s possible to make classic HTML form submissions with Inertia, it’s not recommended since they cause full-page reloads. Instead, it’s better to intercept form submissions and then make the request using Inertia.Server-side Validation
Handling server-side validation errors in Inertia works a little different than handling errors from manual XHR / fetch requests. When making XHR / fetch requests, you typically inspect the response for a422status code and manually update the form’s error state.
However, when using Inertia, a 422 response is never returned by your server. Instead, as we saw in the example above, your routes / controllers will typically return a redirect response - much like a classic, full-page form submission.
For a full discussion on handling and displaying validation errors with Inertia, please consult the validation documentation.
Form Helper
Since working with forms is so common, Inertia includes a form helper designed to help reduce the amount of boilerplate code needed for handling typical form submissions.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.
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()'}.
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.
To reset the form’s values back to their default values, you can use the reset() method.
defaults() method to update them. Then, the form will be reset to the correct values the next time the reset() method is invoked.
isDirty property.
cancel() method.
File Uploads
When making requests or form submissions that include files, Inertia will automatically convert the request data into aFormData object.
For a more thorough discussion of file uploads, please consult 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.