Delegate forms $data validation to Forms::submit #1411
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
$_POST
data is passed toForms\Controller\RestApi::submit
causing an early exit from that function and without being so able to parse$_FILES
data inside the"forms.submit.before"
hookcockpit/modules/Forms/Controller/RestApi.php
Lines 23 to 34 in efb8944
Proposed solution:
Set fallback param
$data
to empty array and delegate empty check validation toForms::submit
function.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
$_POST
is still populated by other input fields.The Upload Form (with just input
$_FILES
) is purely demonstrative. It can be solved somehow by hooking theassets
api, 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