Skip to content

docs: add warning on Validation $data array #7515

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

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,23 @@ Your new custom rule could now be used just like any other rule:
Allowing Parameters
-------------------

If your method needs to work with parameters, the function will need a minimum of three parameters: the value to validate,
the parameter string, and an array with all of the data that was submitted the form. The ``$data`` array is especially handy
If your method needs to work with parameters, the function will need a minimum of three parameters:

1. the value to validate (``$value``)
2. the parameter string (``$params``)
3. an array with all of the data that was submitted the form (``$data``)
4. (optional) a custom error string (``&$error``), just as described above.

.. warning:: The field values in ``$data`` are unvalidated (or may be invalid).
Using unvalidated input data is a source of vulnerability. You must
perform the necessary validation within your custom rules before using the
data in ``$data``.

The ``$data`` array is especially handy
for rules like ``required_with`` that needs to check the value of another submitted field to base its result on:

.. literalinclude:: validation/037.php

Custom errors can be returned as the fourth parameter ``&$error``, just as described above.

.. _validation-using-closure-rule:

Using Closure Rule
Expand Down