Delegate forms $data validation to Forms::submit#1411
Open
Raruto wants to merge 1 commit intoagentejo:nextfrom
Open
Delegate forms $data validation to Forms::submit#1411Raruto wants to merge 1 commit intoagentejo:nextfrom
Raruto wants to merge 1 commit intoagentejo:nextfrom
Conversation
raffaelj
added a commit
to raffaelj/cockpit_FormValidation
that referenced
this pull request
Dec 2, 2022
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.
Preamble
This pull request doesn't alter current forms submission behavior (in essence it ensures that the
"forms.submit.before"event is always triggered for each form submission).A borderline example is shown below.
Issue description:
When using a form call like the following:
empty
$_POSTdata is passed toForms\Controller\RestApi::submitcausing an early exit from that function and without being so able to parse$_FILESdata inside the"forms.submit.before"hookcockpit/modules/Forms/Controller/RestApi.php
Lines 23 to 34 in efb8944
Proposed solution:
Set fallback param
$datato empty array and delegate empty check validation toForms::submitfunction.Example of usage:
Dynamically check and populate forms
$data['files']entry:Contact Form
Simple contact form template with single input
files[]:Lexy template:
Upload Form
Simple contact form template with multiple input
files[]:Lexy template:
Helper Functions
config/bootstrap.php
End notes
The Contact Form example reported above does not suffer from this problem because the variable
$_POSTis still populated by other input fields.The Upload Form (with just input
$_FILES) is purely demonstrative. It can be solved somehow by hooking theassetsapi, however, it would be nice to be able to do it with the same hook (regardless of the number of parameters and without having to define custom rest api endpoints...)Hoping that's clear enough,
Raruto