[6.x] Forms 2: SubmitForm action#14840
Draft
duncanmcclean wants to merge 16 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request extracts the form submission logic from Statamic's FormController into a reusable SubmitForm action class, allowing third-party developers to use it in Livewire components or custom API endpoints.
Usage
Methods:
submit()handles everything from validation, honeypot, file uploads, dispatching the FormSubmitted event and persisting the submission. It returns a Submission instance.validate()validates the data and throws aValidationExceptionon failure.resume()binds an existing incomplete submission so the nextsubmit()call uses it, rather than creating an entirely new submission.The only argument on the
submit()andvalidate()methods scopes validation to a given set of fields. When omitted, the whole form is validated.The
submittinghookThe FormController now has a submitting hook so addons (namely Forms Pro) can take over the submission process.
It may return a response (eg. to return a special payload), a
Submissioninstance (eg. because it handles creating the submission itself) or nothing (which leads to a normal submission).Precognition
Validation used to live in a
FrontendFormRequest, which is where Precognition was handled.However, now that validation lives in the action, the form request has been deleted and Precognition is now handled explicitly in the controller. It validates via the action (scoped to the
Precognition-Validate-Onlyfields) and halts without storing a submission.Laravel's
HandlePrecognitiveRequestsmiddleware short-circuts the controller before its code is executed, so the form route uses a slim HandleFormPrecognitiveRequests subclass which keeps Precognition detection and headers but lets the request reach the controller.Replaces #14375
Depends on #14832
Closes statamic/ideas#1409