-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Can't transform array data in PreSubmit event or DataTransformer #47093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Compound form types expect an array or null on submission, while scalar form types expect a string or null. However, I think you have a valid point. The It seems like a bug to me and after #29307, some As for the solution, I agree to move the submitted data check just after the if ($this->config->getRequestHandler()->isFileUpload($submittedData)) {
if (!$this->config->getOption('allow_file_upload')) {
$submittedData = null;
throw new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
}
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->getOption('multiple', false)) {
$submittedData = null;
throw new TransformationFailedException('Submitted data was expected to be text or number, array given.');
} Handling this should be easy and it should also resolve the mentioned inconsistency, but I might miss something, ping @nicolas-grekas, and @xabbuh as you worked on these two PRs, what do you think? Do you consider this a bug? |
Hey, thanks for your report! |
Could I get a reply or should I close this? |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
I don't think this issue is resolved. |
Symfony version(s) affected
5.4.9 and above
Description
In Form.php there is a check whether the submitted data is an array and if that is the case it is mandated that the form is compound or has the multiple attribute set to true. This check is done before handling the
PRE_SUBMIT
event, which prevents transforming the submitted array to a single value in an event handler (or other data transformers).How to reproduce
Possible Solution
Move the check for compound or multiple, after handling
PRE_SUBMIT
and other data transformation has been handled.Additional Context
In my case data is submitted as json via XMLHttpRequest rather than Html Forms.
symfony/form < 5.4.9 would unintendedly allow arrays if the multiple attribute was present but false.
The text was updated successfully, but these errors were encountered: