13
13
14
14
use Symfony \Component \Form \ChoiceList \View \ChoiceGroupView ;
15
15
use Symfony \Component \Form \ClearableErrorsInterface ;
16
+ use Symfony \Component \Form \FormError ;
16
17
use Symfony \Component \Form \FormInterface ;
17
18
use Symfony \Component \Form \FormView ;
19
+ use Symfony \Component \Form \Util \FormUtil ;
20
+ use Symfony \Component \Form \Util \ServerParams ;
21
+ use Symfony \Component \HttpFoundation \Request ;
18
22
use Symfony \Component \HttpKernel \Exception \UnprocessableEntityHttpException ;
19
23
use Symfony \Contracts \Translation \TranslatableInterface ;
20
24
use Symfony \UX \LiveComponent \Attribute \LiveProp ;
@@ -147,7 +151,7 @@ private function resetForm(bool $soft = false): void
147
151
}
148
152
}
149
153
150
- private function submitForm (bool $ validateAll = true ): void
154
+ private function submitForm (bool $ validateAll = true , ? Request $ request = null ): void
151
155
{
152
156
if (null !== $ this ->formView ) {
153
157
// Two scenarios can cause this:
@@ -160,7 +164,50 @@ private function submitForm(bool $validateAll = true): void
160
164
}
161
165
162
166
$ form = $ this ->getForm ();
163
- $ form ->submit ($ this ->formValues );
167
+ $ method = $ form ->getConfig ()->getMethod ();
168
+
169
+ // For request methods that must not have a request body we fetch data
170
+ // from the query string. Otherwise we look for data in the request body.
171
+ if ('POST ' === $ method && $ request instanceof Request) {
172
+ // Mark the form with an error if the uploaded size was too large
173
+ // This is done here and not in FormValidator because $_POST is
174
+ // empty when that error occurs. Hence the form is never submitted.
175
+ $ serverParams = new ServerParams ();
176
+ if ($ serverParams ->hasPostMaxSizeBeenExceeded ()) {
177
+ // Submit the form, but don't clear the default values
178
+ $ form ->submit (null , false );
179
+
180
+ $ form ->addError (new FormError (
181
+ $ form ->getConfig ()->getOption ('upload_max_size_message ' )(),
182
+ null ,
183
+ ['{{ max }} ' => $ serverParams ->getNormalizedIniPostMaxSize ()]
184
+ ));
185
+
186
+ return ;
187
+ }
188
+
189
+ $ name = $ form ->getName ();
190
+
191
+ if ('' === $ name ) {
192
+ $ params = $ request ->request ->all ();
193
+ $ files = $ request ->files ->all ();
194
+ } elseif ($ request ->request ->has ($ name ) || $ request ->files ->has ($ name )) {
195
+ $ default = $ form ->getConfig ()->getCompound () ? [] : null ;
196
+ $ params = $ request ->request ->all ()[$ name ] ?? $ default ;
197
+ $ files = $ request ->files ->get ($ name , $ default );
198
+ } else {
199
+ // Don't submit the form if it is not present in the request
200
+ return ;
201
+ }
202
+
203
+ if (\is_array ($ params ) && \is_array ($ files )) {
204
+ $ data = FormUtil::mergeParamsAndFiles ($ params , $ files );
205
+ } else {
206
+ $ data = $ params ?: $ files ;
207
+ }
208
+ }
209
+
210
+ $ form ->submit ($ data ?? $ this ->formValues , $ request );
164
211
$ this ->shouldAutoSubmitForm = false ;
165
212
166
213
if ($ validateAll ) {
0 commit comments