1313
1414use Symfony \Component \Form \ChoiceList \View \ChoiceGroupView ;
1515use Symfony \Component \Form \ClearableErrorsInterface ;
16+ use Symfony \Component \Form \FormError ;
1617use Symfony \Component \Form \FormInterface ;
1718use Symfony \Component \Form \FormView ;
19+ use Symfony \Component \Form \Util \FormUtil ;
20+ use Symfony \Component \Form \Util \ServerParams ;
21+ use Symfony \Component \HttpFoundation \Request ;
1822use Symfony \Component \HttpKernel \Exception \UnprocessableEntityHttpException ;
1923use Symfony \Contracts \Translation \TranslatableInterface ;
2024use Symfony \UX \LiveComponent \Attribute \LiveProp ;
@@ -147,7 +151,7 @@ private function resetForm(bool $soft = false): void
147151 }
148152 }
149153
150- private function submitForm (bool $ validateAll = true ): void
154+ private function submitForm (bool $ validateAll = true , ? Request $ request = null ): void
151155 {
152156 if (null !== $ this ->formView ) {
153157 // Two scenarios can cause this:
@@ -160,7 +164,50 @@ private function submitForm(bool $validateAll = true): void
160164 }
161165
162166 $ 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 );
164211 $ this ->shouldAutoSubmitForm = false ;
165212
166213 if ($ validateAll ) {
0 commit comments