Forms
Form
A <form> that takes care of the wiring around the fields: the Livewire action or the URL, the CSRF token and method spoofing, a submit button, the session flash message, the error summary, focus on the first invalid field and a toast after submitting. tk:form.card and tk:form.section are the same form laid out inside a card or a titled section.
Nothing to show
Two fields and a full-width "Send" button under them. Submitting with empty fields shows the validation messages under each field, moves the focus to Name, and shows an error toast. Fields with errors are cleared of their red state as soon as the form is sent again.
Success message #
After a submit without validation errors a success toast says "Profile saved.". The form already has a submit button, so it does not add its own.
Nothing to show
A classic form, without Livewire #
A <form method="POST"> to the profile.update route, with the CSRF token and _method=PUT. A file input inside makes it multipart/form-data. After a redirect back with errors, the page loads with the focus on the first invalid field, and a flashed status message shows as an alert at the top.
Nothing to show
In a card or a section #
The first is a section with the title and description beside the fields (above them on small screens); the second, the fields inside a card with the title in its header. Both behave as tk:form.
Nothing to show
A filter bar #
The fields side by side, each at least 12rem wide and sharing the line, wrapping on narrow screens; the button keeps its own width and lines up with the bottom of the fields.
Nothing to show
View mode #
With readonly the same form shows the values without letting them change: every control is locked, at full opacity and with the normal cursor, and the submit buttons are hidden (the added one is not rendered). Turning $editing on gives back the editable form.
Nothing to show
Card header #
tk:form.card passes description and icon to the card header.
Nothing to show
Error summary #
error-group lists every validation error at the top; set to only, it hides the messages under the fields.
Nothing to show
Session alert #
A flashed status message shows as an alert at the top of the form. alert set to false removes it.
Nothing to show
Customization #
Classes go to the <form>, submit: attributes reach the added button and error-message changes the text of the error toast.
Nothing to show
Reference
tk:form
tk:form.card
tk:form.section
tk:form
| Prop | Type | Default | Description |
|---|---|---|---|
action |
string | from wire:submit |
Inside Livewire, the method called on submit (wire:submit is set for you, submit when there is neither). Outside it, the URL or route name the form posts to; the current URL by default. |
route |
string | null |
A route name for the URL, outside Livewire. |
method |
string | post |
get, post, put, patch or delete. Outside Livewire, the last three are sent as POST with a _method field; inside it the form is GET or POST. |
enctype |
string | auto | The encoding, outside Livewire. Set to multipart/form-data when the form holds a file input. |
readonly |
bool | false |
Locks every control inside in a disabled <fieldset>, keeps them readable (full opacity, normal cursor), hides the submit buttons and adds none. Disabled controls are not sent with the form. |
inline |
bool | false |
Lays the fields and buttons out in a row that wraps, for a filter bar. The session alert and the error summary keep a line of their own, and the added submit button is not full width. |
submit |
bool | true |
Adds a full-width "Send" button at the end when the form has no submit button of its own. false never adds it. |
alert |
bool | slot | true |
Shows the flashed session message (status) as an alert at the top. false removes it; a slot is the alert's body. |
errorGroup |
bool | string | false |
Shows a summary of all validation errors at the top. only shows only the summary, hiding the messages under the fields. |
errorBag |
string | default |
The error bag the fields inside read their messages from. |
focusError |
bool | true |
Moves the focus to the first invalid field after a failed submit; outside Livewire, also on page load when there are errors. |
clearErrorsOnSubmit |
bool | true |
Clears the error state of the fields when the form is sent, inside Livewire. |
toast |
bool | string | error |
Which toasts show after a Livewire submit: error, success, true for both, false for none. With successMessage the default is true. |
errorMessage |
string | There was an error submitting the form. |
The text of the error toast. |
successMessage |
string | Form submitted successfully. |
The text of the success toast; setting it also turns that toast on. |
tk:form.card
Every prop of tk:form, plus the card's: title, subtitle, description, header, footer, prepend, append, actions and size. See Card.
tk:form.section
Every prop of tk:form, plus the section's: title, subtitle, description, prepend, append, actions, separator and size.
Slots
| Tag | Slot | Description |
|---|---|---|
tk:form |
default | The fields and buttons. |
tk:form |
alert |
The body of the session alert. |
tk:form.card, tk:form.section |
default | The fields and buttons. |
tk:form.card, tk:form.section |
alert |
The body of the session alert. |
The card and section slots (header, footer, actions...) work as on those tags.
Customization
Classes and attributes on tk:form go to the <form>. To reach the parts, prefix the attribute:
| Prefix | Tag | Goes to |
|---|---|---|
submit: |
tk:form, tk:form.card, tk:form.section |
The added submit button (submit:label="Save"). |
alert: |
tk:form, tk:form.card, tk:form.section |
The session alert (alert:name="billing" reads another key). |
error-group: |
tk:form, tk:form.card, tk:form.section |
The error summary. |
card: |
tk:form.card |
The card, and its own prefixes (card:title:...); icon, badge, image and the card's prefixes (title:, actions:...) also reach it written as they are. |
section: |
tk:form.section |
The section, and its own prefixes. |
Nothing to show
Accessibility
A native <form> with a native submit button, so Enter in a field submits it. After a failed submit the focus moves to the first invalid field, scrolled into the middle of the screen (without smooth scrolling when the user prefers reduced motion), where its error is announced through aria-describedby.
Behavior notes
- Inside Livewire, the error and success toasts follow the submit action only: other requests made by the page do not show them.
- A submit counts as failed when the response has validation errors or any field inside is marked invalid.
- The "Send" button is added only when no element with
type="submit"is in its content. - Outside Livewire,
GETforms carry no CSRF token. - Inside Livewire the form still has a method (
POSTunlessget), so a submit before Livewire loads does not put the fields in the URL. - Outside Livewire, the submit buttons are disabled while the page posts; see Submit.