Skip to content
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

docs: improve validation.rst #5233

Merged
merged 3 commits into from Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions user_guide_src/source/libraries/validation.rst
Expand Up @@ -33,8 +33,7 @@ On the receiving end, the script must:
be someone else's existing username, or perhaps even a reserved word.
Etc.
#. Sanitize the data for security.
#. Pre-format the data if needed (Does the data need to be trimmed? HTML
encoded? Etc.)
#. Pre-format the data if needed.
#. Prep the data for insertion in the database.

Although there is nothing terribly complex about the above process, it
Expand Down Expand Up @@ -233,7 +232,7 @@ that should be applied::
$validation->setRule('username', 'Username', 'required');

The **field name** must match the key of any data array that is sent in. If
the data is taken directly from $_POST, then it must be an exact match for
the data is taken directly from ``$_POST``, then it must be an exact match for
the form input name.

setRules()
Expand Down Expand Up @@ -440,7 +439,7 @@ Validation Placeholders

The Validation class provides a simple method to replace parts of your rules based on data that's being passed into it. This
sounds fairly obscure but can be especially handy with the ``is_unique`` validation rule. Placeholders are simply
the name of the field (or array key) that was passed in as $data surrounded by curly brackets. It will be
the name of the field (or array key) that was passed in as ``$data`` surrounded by curly brackets. It will be
replaced by the **value** of the matched incoming field. An example should clarify this::

$validation->setRules([
Expand Down Expand Up @@ -687,7 +686,7 @@ a boolean true or false value signifying true if it passed the test or false if
}

By default, the system will look within ``CodeIgniter\Language\en\Validation.php`` for the language strings used
within errors. In custom rules, you may provide error messages by accepting a $error variable by reference in the
within errors. In custom rules, you may provide error messages by accepting a ``$error`` variable by reference in the
second parameter::

public function even(string $str, string &$error = null): bool
Expand All @@ -711,7 +710,7 @@ Allowing Parameters
===================

If your method needs to work with parameters, the function will need a minimum of three parameters: the string to validate,
the parameter string, and an array with all of the data that was submitted the form. The $data array is especially handy
the parameter string, and an array with all of the data that was submitted the form. The ``$data`` array is especially handy
for rules like ``require_with`` that needs to check the value of another submitted field to base its result on::

public function required_with($str, string $fields, array $data): bool
Expand Down Expand Up @@ -929,6 +928,6 @@ is_image Yes Fails if the file cannot be determined to be

The file validation rules apply for both single and multiple file uploads.

.. note:: You can also use any native PHP functions that permit up
to two parameters, where at least one is required (to pass
the field data).
.. note:: You can also use any native PHP functions that return boolean and
permit at least one parameter, the field data to validate.
The Validation library **never alters the data** to validate.