11.. _validation :
22
33Validation
4- ##################################################
4+ ##########
55
66CodeIgniter provides a comprehensive data validation class that
77helps minimize the amount of code you'll write.
@@ -11,7 +11,7 @@ helps minimize the amount of code you'll write.
1111 :depth: 2
1212
1313Overview
14- ************************************************
14+ ********
1515
1616Before explaining CodeIgniter's approach to data validation, let's
1717describe the ideal scenario:
@@ -43,7 +43,7 @@ HTML. Form validation, while simple to create, is generally very messy
4343and tedious to implement.
4444
4545Form Validation Tutorial
46- ************************************************
46+ ************************
4747
4848What follows is a "hands on" tutorial for implementing CodeIgniter's Form
4949Validation.
@@ -60,7 +60,7 @@ Let's create those three things, using a member sign-up form as the
6060example.
6161
6262The Form
63- ================================================
63+ ========
6464
6565Using a text editor, create a form called **Signup.php **. In it, place this
6666code and save it to your **app/Views/ ** folder::
@@ -95,7 +95,7 @@ code and save it to your **app/Views/** folder::
9595 </html>
9696
9797The Success Page
98- ================================================
98+ ================
9999
100100Using a text editor, create a form called **Success.php **. In it, place
101101this code and save it to your **app/Views/ ** folder::
@@ -114,15 +114,15 @@ this code and save it to your **app/Views/** folder::
114114 </html>
115115
116116The Controller
117- ================================================
117+ ==============
118118
119119Using a text editor, create a controller called **Form.php **. In it, place
120120this code and save it to your **app/Controllers/ ** folder:
121121
122122.. literalinclude :: validation/001.php
123123
124124Try it!
125- ================================================
125+ =======
126126
127127To try your form, visit your site using a URL similar to this one::
128128
@@ -140,7 +140,7 @@ the **Validation class** inside. See :ref:`controllers-validating-data`.
140140 any of them failing.
141141
142142Explanation
143- ================================================
143+ ===========
144144
145145You'll notice several things about the above pages:
146146
@@ -166,7 +166,7 @@ Based on whether the validation was successful it either presents the
166166form or the success page.
167167
168168Add Validation Rules
169- ================================================
169+ ====================
170170
171171Then add validation rules in the controller (**Form.php **):
172172
@@ -206,7 +206,7 @@ If you want to use these rules, you need to change the rule classes in **app/Con
206206.. literalinclude :: validation/003.php
207207
208208Loading the Library
209- ************************************************
209+ *******************
210210
211211The library is loaded as a service named **validation **:
212212
@@ -219,7 +219,7 @@ for including multiple Rulesets, and collections of rules that can be easily reu
219219 the :doc: `Model </models/model >` provide methods to make validation even easier.
220220
221221Setting Validation Rules
222- ************************************************
222+ ************************
223223
224224CodeIgniter lets you set as many validation rules as you need for a
225225given field, cascading them in order. To set validation rules you
@@ -268,10 +268,10 @@ data to be validated:
268268.. literalinclude :: validation/008.php
269269
270270Working with Validation
271- ************************************************
271+ ***********************
272272
273273Validating Keys that are Arrays
274- ================================================
274+ ===============================
275275
276276If your data is in a nested associative array, you can use "dot array syntax" to
277277easily validate your data:
@@ -288,14 +288,14 @@ For example, data returned by multi select dropdown:
288288.. literalinclude :: validation/011.php
289289
290290Validate 1 Value
291- ================================================
291+ ================
292292
293293Validate one value against a rule:
294294
295295.. literalinclude :: validation/012.php
296296
297297Saving Sets of Validation Rules to the Config File
298- =======================================================
298+ ==================================================
299299
300300A nice feature of the Validation class is that it permits you to store all
301301your validation rules for your entire application in a config file. You organize
@@ -305,7 +305,7 @@ the validation.
305305.. _validation-array :
306306
307307How to save your rules
308- -------------------------------------------------------
308+ ----------------------
309309
310310To store your validation rules, simply create a new public property in the ``Config\Validation ``
311311class with the name of your group. This element will hold an array with your validation
@@ -330,7 +330,7 @@ Or pass all settings in an array:
330330See below for details on the formatting of the array.
331331
332332Getting & Setting Rule Groups
333- -------------------------------------------------------
333+ -----------------------------
334334
335335**Get Rule Group **
336336
@@ -345,7 +345,7 @@ This method sets a rule group from the validation configuration to the validatio
345345.. literalinclude :: validation/018.php
346346
347347Running Multiple Validations
348- =======================================================
348+ ============================
349349
350350.. note :: ``run()`` method will not reset error state. Should a previous run fail,
351351 ``run() `` will always return false and ``getErrors() `` will return
@@ -359,7 +359,7 @@ you previously set, so ``setRules()``, ``setRuleGroup()`` etc. need to be repeat
359359.. literalinclude :: validation/019.php
360360
361361Validation Placeholders
362- =======================================================
362+ =======================
363363
364364The Validation class provides a simple method to replace parts of your rules based on data that's being passed into it. This
365365sounds fairly obscure but can be especially handy with the ``is_unique `` validation rule. Placeholders are simply
@@ -383,7 +383,7 @@ This can also be used to create more dynamic rules at runtime, as long as you ta
383383keys passed in don't conflict with your form data.
384384
385385Working With Errors
386- ************************************************
386+ *******************
387387
388388The Validation library provides several methods to help you set error messages, provide
389389custom error messages, and retrieve one or more errors to display.
@@ -535,7 +535,7 @@ right after the name of the field the error should belong to::
535535 <?= $validation->showError('username', 'my_single') ?>
536536
537537Creating Custom Rules
538- ************************************************
538+ *********************
539539
540540Rules are stored within simple, namespaced classes. They can be stored any location you would like, as long as the
541541autoloader can find it. These files are called RuleSets. To add a new RuleSet, edit **Config/Validation.php ** and
0 commit comments