@@ -265,8 +265,11 @@ given field, cascading them in order. To set validation rules you
265265will use the ``setRule() ``, ``setRules() ``, or ``withRequest() ``
266266methods.
267267
268+ Setting a Single Rule
269+ =====================
270+
268271setRule()
269- =========
272+ ---------
270273
271274This method sets a single rule. It has the method signature::
272275
@@ -285,8 +288,11 @@ the form input name.
285288 broken in extending classes overriding this method, the child class's method should also be modified
286289 to remove the typehint.
287290
291+ Setting Multiple Rules
292+ ======================
293+
288294setRules()
289- ==========
295+ ----------
290296
291297Like ``setRule() ``, but accepts an array of field names and their rules:
292298
@@ -298,6 +304,23 @@ To give a labeled error message you can set up as:
298304
299305.. _validation-withrequest :
300306
307+ Setting Rules for Array Data
308+ ============================
309+
310+ If your data is in a nested associative array, you can use "dot array syntax" to
311+ easily validate your data:
312+
313+ .. literalinclude :: validation/009.php
314+
315+ You can use the ``* `` wildcard symbol to match any one level of the array:
316+
317+ .. literalinclude :: validation/010.php
318+
319+ "dot array syntax" can also be useful when you have single dimension array data.
320+ For example, data returned by multi select dropdown:
321+
322+ .. literalinclude :: validation/011.php
323+
301324withRequest()
302325=============
303326
@@ -321,25 +344,37 @@ data to be validated:
321344Working with Validation
322345***********************
323346
324- Validating Keys that are Arrays
325- ===============================
347+ Running Validation
348+ ==================
326349
327- If your data is in a nested associative array, you can use "dot array syntax" to
328- easily validate your data:
350+ The ``run() `` method runs validation. It has the method signature::
329351
330- .. literalinclude :: validation/009.php
352+ run(?array $data = null, ?string $group = null, ?string $dbGroup = null): bool
331353
332- You can use the '*' wildcard symbol to match any one level of the array:
354+ The ``$data `` is an array of data to validate. The optional second parameter
355+ ``$group `` is the :ref: `predefined group of rules <validation-array >` to apply.
356+ The optional third parameter ``$dbGroup `` is the database group to use.
333357
334- .. literalinclude :: validation/010.php
358+ This method returns true if the validation is successful.
335359
336- "dot array syntax" can also be useful when you have single dimension array data.
337- For example, data returned by multi select dropdown:
360+ .. literalinclude :: validation/043.php
338361
339- .. literalinclude :: validation/011.php
362+ Running Multiple Validations
363+ ============================
340364
341- Validate 1 Value
342- ================
365+ .. note :: ``run()`` method will not reset error state. Should a previous run fail,
366+ ``run() `` will always return false and ``getErrors() `` will return
367+ all previous errors until explicitly reset.
368+
369+ If you intend to run multiple validations, for instance on different data sets or with different
370+ rules after one another, you might need to call ``$validation->reset() `` before each run to get rid of
371+ errors from previous run. Be aware that ``reset() `` will invalidate any data, rule or custom error
372+ you previously set, so ``setRules() ``, ``setRuleGroup() `` etc. need to be repeated:
373+
374+ .. literalinclude :: validation/019.php
375+
376+ Validating 1 Value
377+ ==================
343378
344379Validate one value against a rule:
345380
@@ -355,7 +390,7 @@ the validation.
355390
356391.. _validation-array :
357392
358- How to save your rules
393+ How to Save Your Rules
359394----------------------
360395
361396To store your validation rules, simply create a new public property in the ``Config\Validation ``
@@ -364,10 +399,16 @@ rules. As shown earlier, the validation array will have this prototype:
364399
365400.. literalinclude :: validation/013.php
366401
402+ How to Specify Rule Group
403+ -------------------------
404+
367405You can specify the group to use when you call the ``run() `` method:
368406
369407.. literalinclude :: validation/014.php
370408
409+ How to Save Error Messages
410+ --------------------------
411+
371412You can also store custom error messages in this configuration file by naming the
372413property the same as the group, and appended with ``_errors ``. These will automatically
373414be used for any errors when this group is used:
@@ -378,7 +419,7 @@ Or pass all settings in an array:
378419
379420.. literalinclude :: validation/016.php
380421
381- See below for details on the formatting of the array.
422+ See :ref: ` validation-custom-errors ` for details on the formatting of the array.
382423
383424Getting & Setting Rule Groups
384425-----------------------------
@@ -395,20 +436,6 @@ This method sets a rule group from the validation configuration to the validatio
395436
396437.. literalinclude :: validation/018.php
397438
398- Running Multiple Validations
399- ============================
400-
401- .. note :: ``run()`` method will not reset error state. Should a previous run fail,
402- ``run() `` will always return false and ``getErrors() `` will return
403- all previous errors until explicitly reset.
404-
405- If you intend to run multiple validations, for instance on different data sets or with different
406- rules after one another, you might need to call ``$validation->reset() `` before each run to get rid of
407- errors from previous run. Be aware that ``reset() `` will invalidate any data, rule or custom error
408- you previously set, so ``setRules() ``, ``setRuleGroup() `` etc. need to be repeated:
409-
410- .. literalinclude :: validation/019.php
411-
412439Validation Placeholders
413440=======================
414441
0 commit comments