@@ -35,13 +35,6 @@ abstract class FormRequest
3535 */
3636 private array $ validatedData = [];
3737
38- /**
39- * Data after prepareForValidation() and before validation rules run.
40- *
41- * @var array<string, mixed>
42- */
43- private array $ preparedValidationData = [];
44-
4538 /**
4639 * When called by the framework, the current IncomingRequest is injected
4740 * explicitly. When instantiated manually (e.g. in tests), the constructor
@@ -150,21 +143,6 @@ protected function prepareForValidation(array $data): array
150143 return $ data ;
151144 }
152145
153- /**
154- * Returns the data after prepareForValidation() has run.
155- *
156- * This is useful in failedValidation() when a custom failure response needs
157- * the same prepared data that was passed to validation. This data has not
158- * passed validation; use getValidated() or getValidatedInput() after
159- * successful validation for trusted values.
160- *
161- * @return array<string, mixed>
162- */
163- protected function getPreparedValidationData (): array
164- {
165- return $ this ->preparedValidationData ;
166- }
167-
168146 /**
169147 * Called when validation fails. Override to customize the failure response.
170148 *
@@ -175,14 +153,27 @@ protected function getPreparedValidationData(): array
175153 * returns a 422 JSON response instead.
176154 *
177155 * @param array<string, string> $errors
156+ * @param array<string, mixed> $preparedData
178157 */
179- protected function failedValidation (array $ errors ): ResponseInterface
158+ protected function failedValidation (array $ errors, array $ preparedData ): ResponseInterface
180159 {
181160 if ($ this ->shouldReturnJsonResponse ()) {
182161 return service ('response ' )->setStatusCode (422 )->setJSON (['errors ' => $ errors ]);
183162 }
184163
185- return redirect ()->back ()->withInput ();
164+ $ redirect = redirect ()->back ()->withInput ();
165+
166+ $ key = in_array ($ this ->request ->getMethod (), [Method::GET , Method::HEAD ], true )
167+ ? 'get '
168+ : 'post ' ;
169+
170+ service ('session ' )->setFlashdata ('_ci_old_input ' , [
171+ 'get ' => [],
172+ 'post ' => [],
173+ $ key => $ preparedData ,
174+ ]);
175+
176+ return $ redirect ;
186177 }
187178
188179 /**
@@ -271,20 +262,19 @@ protected function validationData(): array
271262 */
272263 final public function resolveRequest (): ?ResponseInterface
273264 {
274- $ this ->validatedData = [];
275- $ this ->preparedValidationData = [];
265+ $ this ->validatedData = [];
276266
277267 if (! $ this ->isAuthorized ()) {
278268 return $ this ->failedAuthorization ();
279269 }
280270
281- $ this -> preparedValidationData = $ this ->prepareForValidation ($ this ->validationData ());
271+ $ data = $ this ->prepareForValidation ($ this ->validationData ());
282272
283273 $ validation = service ('validation ' )
284274 ->setRules ($ this ->rules (), $ this ->messages ());
285275
286- if (! $ validation ->run ($ this -> preparedValidationData )) {
287- return $ this ->failedValidation ($ validation ->getErrors ());
276+ if (! $ validation ->run ($ data )) {
277+ return $ this ->failedValidation ($ validation ->getErrors (), $ data );
288278 }
289279
290280 $ this ->validatedData = $ validation ->getValidated ();
0 commit comments