Skip to content

Commit

Permalink
Merge pull request codeigniter4#8331 from kenjis/docs-update-valiatio…
Browse files Browse the repository at this point in the history
…n-sample

docs: use validateData() instead of validate() in Validation
  • Loading branch information
kenjis authored Dec 14, 2023
2 parents f81dd1a + 50f7633 commit ad0fb2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ To try your form, visit your site using a URL similar to this one::
example.com/index.php/form/

If you submit the form you should simply see the form reload. That's
because you haven't set up any validation rules in ``$this->validate()`` yet.
because you haven't set up any validation rules in :ref:`controller-validatedata` yet.

The ``validate()`` method is a method in the Controller. It uses
the **Validation class** inside. See :ref:`controllers-validating-data`.
The ``validateData()`` method is a method in the Controller. It uses
the **Validation class** inside. See :ref:`controller-validatedata`.

.. note:: Since you haven't told the ``validate()`` method to validate anything
yet, it **returns false** (boolean false) **by default**. The ``validate()``
.. note:: Since you haven't told the ``validateData()`` method to validate anything
yet, it **returns false** (boolean false) **by default**. The ``validateData()``
method only returns true if it has successfully applied your rules without
any of them failing.

Expand Down Expand Up @@ -189,7 +189,7 @@ It loads the form helper used by your view files.

The controller has one method: ``index()``. This method returns
the **signup** view to show the form when a non-POST request comes. Otherwise, it
uses the Controller-provided ``validate()`` method. It also runs the validation routine.
uses the Controller-provided :ref:`controller-validatedata` method. It also runs the validation routine.
Based on whether the validation was successful it either presents the
form or the success page.

Expand Down
8 changes: 6 additions & 2 deletions user_guide_src/source/libraries/validation/001.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ public function index()
return view('signup');
}

$rules = [];
$rules = [
// @TODO
];

if (! $this->validate($rules)) {
$data = $this->request->getPost(array_keys($rules));

if (! $this->validateData($data, $rules)) {
return view('signup');
}

Expand Down

0 comments on commit ad0fb2c

Please sign in to comment.