Skip to content

feat: expose prepared FormRequest data during validation failure#10259

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/formrequest-prepared-validation-data
Open

feat: expose prepared FormRequest data during validation failure#10259
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/formrequest-prepared-validation-data

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

Description

This PR proposes making the prepared FormRequest payload available while handling validation failure.

When a FormRequest normalizes input in prepareForValidation(), that prepared data is what the validator actually checks. But if validation fails, failedValidation() did not have a clean way to access that same payload. The user guide example for flashing normalized old input had to call prepareForValidation($this->validationData()) a second time just to rebuild it, which felt a bit off.

This PR stores the prepared validation data when the FormRequest is resolved, and exposes it to subclasses with getPreparedValidationData(). That gives custom failedValidation() implementations access to the exact payload that was passed to validation, without running preparation twice.

The main use case is small and practical: if a request trims or canonicalizes visible form fields, a custom failure response can flash those prepared values back to the form instead of flashing raw submitted input.

This does not change the default validation failure response. Also, the prepared payload is still not trusted data; successful requests should continue using getValidated() or getValidatedInput().

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- Store prepared validation data before running FormRequest validation
- Allow failedValidation() overrides to reuse the exact prepared payload
- Avoid calling prepareForValidation() a second time in custom failure responses
- Document normalized old-input handling

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@memleakd memleakd changed the title feat: expose prepared FormRequest data during validation failure feat: expose prepared FormRequest data during validation failure May 31, 2026
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant