1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
|
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Validation — CodeIgniter 3.1.7 documentation</title>
<link rel="shortcut icon" href="../_static/ci-icon.ico"/>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
<link rel="index" title="Index"
href="../genindex.html"/>
<link rel="search" title="Search" href="../search.html"/>
<link rel="top" title="CodeIgniter 3.1.7 documentation" href="../index.html"/>
<link rel="up" title="Libraries" href="index.html"/>
<link rel="next" title="FTP Class" href="ftp.html"/>
<link rel="prev" title="File Uploading Class" href="file_uploading.html"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div id="nav">
<div id="nav_inner">
<div id="pulldown-menu" class="ciNav">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
</ul>
</li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
<li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
<li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Form Validation</a></li>
<li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li>
<li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="nav2">
<a href="#" id="openToc">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
</a>
</div>
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="../index.html" class="fa fa-home"> CodeIgniter</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
<li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
<li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
</ul>
</li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
<li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
<li class="toctree-l2"><a class="reference internal" href="file_uploading.html">File Uploading Class</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Form Validation</a></li>
<li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li>
<li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
<li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">CodeIgniter</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> »</li>
<li><a href="index.html">Libraries</a> »</li>
<li>Form Validation</li>
<li class="wy-breadcrumbs-aside">
</li>
<div style="float:right;margin-left:5px;" id="closeMe">
<img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
</div>
</ul>
<hr/>
</div>
<div role="main" class="document">
<div class="section" id="form-validation">
<h1><a class="toc-backref" href="#id6">Form Validation</a><a class="headerlink" href="#form-validation" title="Permalink to this headline">¶</a></h1>
<p>CodeIgniter provides a comprehensive form validation and data prepping
class that helps minimize the amount of code you’ll write.</p>
<div class="contents topic" id="page-contents">
<p class="topic-title first">Page Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#form-validation" id="id6">Form Validation</a><ul>
<li><a class="reference internal" href="#overview" id="id7">Overview</a></li>
<li><a class="reference internal" href="#form-validation-tutorial" id="id8">Form Validation Tutorial</a><ul>
<li><a class="reference internal" href="#the-form" id="id9">The Form</a></li>
<li><a class="reference internal" href="#the-success-page" id="id10">The Success Page</a></li>
<li><a class="reference internal" href="#the-controller" id="id11">The Controller</a></li>
<li><a class="reference internal" href="#try-it" id="id12">Try it!</a></li>
<li><a class="reference internal" href="#explanation" id="id13">Explanation</a></li>
<li><a class="reference internal" href="#setting-validation-rules" id="id14">Setting Validation Rules</a></li>
<li><a class="reference internal" href="#setting-rules-using-an-array" id="id15">Setting Rules Using an Array</a></li>
<li><a class="reference internal" href="#cascading-rules" id="id16">Cascading Rules</a></li>
<li><a class="reference internal" href="#prepping-data" id="id17">Prepping Data</a></li>
<li><a class="reference internal" href="#re-populating-the-form" id="id18">Re-populating the form</a></li>
<li><a class="reference internal" href="#callbacks-your-own-validation-methods" id="id19">Callbacks: Your own Validation Methods</a></li>
<li><a class="reference internal" href="#callable-use-anything-as-a-rule" id="id20">Callable: Use anything as a rule</a></li>
<li><a class="reference internal" href="#setting-error-messages" id="id21">Setting Error Messages</a></li>
<li><a class="reference internal" href="#translating-field-names" id="id22">Translating Field Names</a></li>
<li><a class="reference internal" href="#changing-the-error-delimiters" id="id23">Changing the Error Delimiters</a></li>
<li><a class="reference internal" href="#showing-errors-individually" id="id24">Showing Errors Individually</a></li>
<li><a class="reference internal" href="#validating-an-array-other-than-post" id="id25">Validating an Array (other than $_POST)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#saving-sets-of-validation-rules-to-a-config-file" id="id26">Saving Sets of Validation Rules to a Config File</a><ul>
<li><a class="reference internal" href="#how-to-save-your-rules" id="id27">How to save your rules</a></li>
<li><a class="reference internal" href="#creating-sets-of-rules" id="id28">Creating Sets of Rules</a></li>
<li><a class="reference internal" href="#calling-a-specific-rule-group" id="id29">Calling a Specific Rule Group</a></li>
<li><a class="reference internal" href="#associating-a-controller-method-with-a-rule-group" id="id30">Associating a Controller Method with a Rule Group</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-arrays-as-field-names" id="id31">Using Arrays as Field Names</a></li>
<li><a class="reference internal" href="#rule-reference" id="id32">Rule Reference</a></li>
<li><a class="reference internal" href="#prepping-reference" id="id33">Prepping Reference</a></li>
<li><a class="reference internal" href="#class-reference" id="id34">Class Reference</a></li>
<li><a class="reference internal" href="#helper-reference" id="id35">Helper Reference</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="overview">
<h2><a class="toc-backref" href="#id7">Overview</a><a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>Before explaining CodeIgniter’s approach to data validation, let’s
describe the ideal scenario:</p>
<ol class="arabic simple">
<li>A form is displayed.</li>
<li>You fill it in and submit it.</li>
<li>If you submitted something invalid, or perhaps missed a required
item, the form is redisplayed containing your data along with an
error message describing the problem.</li>
<li>This process continues until you have submitted a valid form.</li>
</ol>
<p>On the receiving end, the script must:</p>
<ol class="arabic simple">
<li>Check for required data.</li>
<li>Verify that the data is of the correct type, and meets the correct
criteria. For example, if a username is submitted it must be
validated to contain only permitted characters. It must be of a
minimum length, and not exceed a maximum length. The username can’t
be someone else’s existing username, or perhaps even a reserved word.
Etc.</li>
<li>Sanitize the data for security.</li>
<li>Pre-format the data if needed (Does the data need to be trimmed? HTML
encoded? Etc.)</li>
<li>Prep the data for insertion in the database.</li>
</ol>
<p>Although there is nothing terribly complex about the above process, it
usually requires a significant amount of code, and to display error
messages, various control structures are usually placed within the form
HTML. Form validation, while simple to create, is generally very messy
and tedious to implement.</p>
</div>
<div class="section" id="form-validation-tutorial">
<h2><a class="toc-backref" href="#id8">Form Validation Tutorial</a><a class="headerlink" href="#form-validation-tutorial" title="Permalink to this headline">¶</a></h2>
<p>What follows is a “hands on” tutorial for implementing CodeIgniters Form
Validation.</p>
<p>In order to implement form validation you’ll need three things:</p>
<ol class="arabic simple">
<li>A <a class="reference internal" href="../general/views.html"><span class="doc">View</span></a> file containing a form.</li>
<li>A View file containing a “success” message to be displayed upon
successful submission.</li>
<li>A <a class="reference internal" href="../general/controllers.html"><span class="doc">controller</span></a> method to receive and
process the submitted data.</li>
</ol>
<p>Let’s create those three things, using a member sign-up form as the
example.</p>
<div class="section" id="the-form">
<h3><a class="toc-backref" href="#id9">The Form</a><a class="headerlink" href="#the-form" title="Permalink to this headline">¶</a></h3>
<p>Using a text editor, create a form called myform.php. In it, place this
code and save it to your application/views/ folder:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">html</span><span class="o">></span>
<span class="o"><</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">title</span><span class="o">></span><span class="nx">My</span> <span class="nx">Form</span><span class="o"></</span><span class="nx">title</span><span class="o">></span>
<span class="o"></</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">body</span><span class="o">></span>
<span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">validation_errors</span><span class="p">();</span> <span class="cp">?></span>
<span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">form_open</span><span class="p">(</span><span class="s1">'form'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Username<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">value</span><span class="o">=</span><span class="s">""</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">value</span><span class="o">=</span><span class="s">""</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password Confirm<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"passconf"</span> <span class="na">value</span><span class="o">=</span><span class="s">""</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Email Address<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"email"</span> <span class="na">value</span><span class="o">=</span><span class="s">""</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">div</span><span class="p">><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Submit"</span> <span class="p">/></</span><span class="nt">div</span><span class="p">></span>
<span class="p"></</span><span class="nt">form</span><span class="p">></span>
<span class="p"></</span><span class="nt">body</span><span class="p">></span>
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
</pre></div>
</div>
</div>
<div class="section" id="the-success-page">
<h3><a class="toc-backref" href="#id10">The Success Page</a><a class="headerlink" href="#the-success-page" title="Permalink to this headline">¶</a></h3>
<p>Using a text editor, create a form called formsuccess.php. In it, place
this code and save it to your application/views/ folder:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">html</span><span class="o">></span>
<span class="o"><</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">title</span><span class="o">></span><span class="nx">My</span> <span class="nx">Form</span><span class="o"></</span><span class="nx">title</span><span class="o">></span>
<span class="o"></</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">body</span><span class="o">></span>
<span class="o"><</span><span class="nx">h3</span><span class="o">></span><span class="nx">Your</span> <span class="nx">form</span> <span class="nx">was</span> <span class="nx">successfully</span> <span class="nx">submitted</span><span class="o">!</</span><span class="nx">h3</span><span class="o">></span>
<span class="o"><</span><span class="nx">p</span><span class="o">><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">anchor</span><span class="p">(</span><span class="s1">'form'</span><span class="p">,</span> <span class="s1">'Try it again!'</span><span class="p">);</span> <span class="cp">?></span><span class="p"></</span><span class="nt">p</span><span class="p">></span>
<span class="p"></</span><span class="nt">body</span><span class="p">></span>
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
</pre></div>
</div>
</div>
<div class="section" id="the-controller">
<h3><a class="toc-backref" href="#id11">The Controller</a><a class="headerlink" href="#the-controller" title="Permalink to this headline">¶</a></h3>
<p>Using a text editor, create a controller called Form.php. In it, place
this code and save it to your application/controllers/ folder:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span>
<span class="k">class</span> <span class="nc">Form</span> <span class="k">extends</span> <span class="nx">CI_Controller</span> <span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">index</span><span class="p">()</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">helper</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'form'</span><span class="p">,</span> <span class="s1">'url'</span><span class="p">));</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">library</span><span class="p">(</span><span class="s1">'form_validation'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">run</span><span class="p">()</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'myform'</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'formsuccess'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="try-it">
<h3><a class="toc-backref" href="#id12">Try it!</a><a class="headerlink" href="#try-it" title="Permalink to this headline">¶</a></h3>
<p>To try your form, visit your site using a URL similar to this one:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">example</span><span class="o">.</span><span class="nx">com</span><span class="o">/</span><span class="nx">index</span><span class="o">.</span><span class="nx">php</span><span class="o">/</span><span class="nx">form</span><span class="o">/</span>
</pre></div>
</div>
<p>If you submit the form you should simply see the form reload. That’s
because you haven’t set up any validation rules yet.</p>
<p><strong>Since you haven’t told the Form Validation class to validate anything
yet, it returns FALSE (boolean false) by default. ``The run()`` method
only returns TRUE if it has successfully applied your rules without any
of them failing.</strong></p>
</div>
<div class="section" id="explanation">
<h3><a class="toc-backref" href="#id13">Explanation</a><a class="headerlink" href="#explanation" title="Permalink to this headline">¶</a></h3>
<p>You’ll notice several things about the above pages:</p>
<p>The form (myform.php) is a standard web form with a couple exceptions:</p>
<ol class="arabic">
<li><p class="first">It uses a form helper to create the form opening. Technically, this
isn’t necessary. You could create the form using standard HTML.
However, the benefit of using the helper is that it generates the
action URL for you, based on the URL in your config file. This makes
your application more portable in the event your URLs change.</p>
</li>
<li><p class="first">At the top of the form you’ll notice the following function call:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">validation_errors</span><span class="p">();</span> <span class="cp">?></span>
</pre></div>
</div>
<p>This function will return any error messages sent back by the
validator. If there are no messages it returns an empty string.</p>
</li>
</ol>
<p>The controller (Form.php) has one method: <code class="docutils literal"><span class="pre">index()</span></code>. This method
initializes the validation class and loads the form helper and URL
helper used by your view files. It also runs the validation routine.
Based on whether the validation was successful it either presents the
form or the success page.</p>
</div>
<div class="section" id="setting-validation-rules">
<span id="id1"></span><h3><a class="toc-backref" href="#id14">Setting Validation Rules</a><a class="headerlink" href="#setting-validation-rules" title="Permalink to this headline">¶</a></h3>
<p>CodeIgniter lets you set as many validation rules as you need for a
given field, cascading them in order, and it even lets you prep and
pre-process the field data at the same time. To set validation rules you
will use the <code class="docutils literal"><span class="pre">set_rules()</span></code> method:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">();</span>
</pre></div>
</div>
<p>The above method takes <strong>three</strong> parameters as input:</p>
<ol class="arabic simple">
<li>The field name - the exact name you’ve given the form field.</li>
<li>A “human” name for this field, which will be inserted into the error
message. For example, if your field is named “user” you might give it
a human name of “Username”.</li>
<li>The validation rules for this form field.</li>
<li>(optional) Set custom error messages on any rules given for current field. If not provided will use the default one.</li>
</ol>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you would like the field name to be stored in a language
file, please see <a class="reference internal" href="#translating-field-names"><span class="std std-ref">Translating Field Names</span></a>.</p>
</div>
<p>Here is an example. In your controller (Form.php), add this code just
below the validation initialization method:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="s1">'Password'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">,</span> <span class="s1">'Password Confirmation'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'email'</span><span class="p">,</span> <span class="s1">'Email'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
</pre></div>
</div>
<p>Your controller should now look like this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span>
<span class="k">class</span> <span class="nc">Form</span> <span class="k">extends</span> <span class="nx">CI_Controller</span> <span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">index</span><span class="p">()</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">helper</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'form'</span><span class="p">,</span> <span class="s1">'url'</span><span class="p">));</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">library</span><span class="p">(</span><span class="s1">'form_validation'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="s1">'Password'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span><span class="s1">'required'</span> <span class="o">=></span> <span class="s1">'You must provide a %s.'</span><span class="p">)</span>
<span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">,</span> <span class="s1">'Password Confirmation'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'email'</span><span class="p">,</span> <span class="s1">'Email'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">run</span><span class="p">()</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'myform'</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'formsuccess'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Now submit the form with the fields blank and you should see the error
messages. If you submit the form with all the fields populated you’ll
see your success page.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The form fields are not yet being re-populated with the data
when there is an error. We’ll get to that shortly.</p>
</div>
</div>
<div class="section" id="setting-rules-using-an-array">
<h3><a class="toc-backref" href="#id15">Setting Rules Using an Array</a><a class="headerlink" href="#setting-rules-using-an-array" title="Permalink to this headline">¶</a></h3>
<p>Before moving on it should be noted that the rule setting method can
be passed an array if you prefer to set all your rules in one action. If
you use this approach, you must name your array keys as indicated:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'username'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'password'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span><span class="p">,</span>
<span class="s1">'errors'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span> <span class="o">=></span> <span class="s1">'You must provide a %s.'</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'passconf'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password Confirmation'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'email'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Email'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">)</span>
<span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="nv">$config</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="cascading-rules">
<h3><a class="toc-backref" href="#id16">Cascading Rules</a><a class="headerlink" href="#cascading-rules" title="Permalink to this headline">¶</a></h3>
<p>CodeIgniter lets you pipe multiple rules together. Let’s try it. Change
your rules in the third parameter of rule setting method, like this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span>
<span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="s1">'required|min_length[5]|max_length[12]|is_unique[users.username]'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span> <span class="o">=></span> <span class="s1">'You have not provided %s.'</span><span class="p">,</span>
<span class="s1">'is_unique'</span> <span class="o">=></span> <span class="s1">'This %s already exists.'</span>
<span class="p">)</span>
<span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="s1">'Password'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">,</span> <span class="s1">'Password Confirmation'</span><span class="p">,</span> <span class="s1">'required|matches[password]'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'email'</span><span class="p">,</span> <span class="s1">'Email'</span><span class="p">,</span> <span class="s1">'required|valid_email|is_unique[users.email]'</span><span class="p">);</span>
</pre></div>
</div>
<p>The above code sets the following rules:</p>
<ol class="arabic simple">
<li>The username field be no shorter than 5 characters and no longer than
12.</li>
<li>The password field must match the password confirmation field.</li>
<li>The email field must contain a valid email address.</li>
</ol>
<p>Give it a try! Submit your form without the proper data and you’ll see
new error messages that correspond to your new rules. There are numerous
rules available which you can read about in the validation reference.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>You can also pass an array of rules to <code class="docutils literal"><span class="pre">set_rules()</span></code>,
instead of a string. Example:</p>
<div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">'required'</span><span class="p">,</span> <span class="s1">'min_length[5]'</span><span class="p">));</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="prepping-data">
<h3><a class="toc-backref" href="#id17">Prepping Data</a><a class="headerlink" href="#prepping-data" title="Permalink to this headline">¶</a></h3>
<p>In addition to the validation method like the ones we used above, you
can also prep your data in various ways. For example, you can set up
rules like this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="s1">'trim|required|min_length[5]|max_length[12]'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="s1">'Password'</span><span class="p">,</span> <span class="s1">'trim|required|min_length[8]'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">,</span> <span class="s1">'Password Confirmation'</span><span class="p">,</span> <span class="s1">'trim|required|matches[password]'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'email'</span><span class="p">,</span> <span class="s1">'Email'</span><span class="p">,</span> <span class="s1">'trim|required|valid_email'</span><span class="p">);</span>
</pre></div>
</div>
<p>In the above example, we are “trimming” the fields, checking for length
where necessary and making sure that both password fields match.</p>
<p><strong>Any native PHP function that accepts one parameter can be used as a
rule, like ``htmlspecialchars()``, ``trim()``, etc.</strong></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You will generally want to use the prepping functions
<strong>after</strong> the validation rules so if there is an error, the
original data will be shown in the form.</p>
</div>
</div>
<div class="section" id="re-populating-the-form">
<h3><a class="toc-backref" href="#id18">Re-populating the form</a><a class="headerlink" href="#re-populating-the-form" title="Permalink to this headline">¶</a></h3>
<p>Thus far we have only been dealing with errors. It’s time to repopulate
the form field with the submitted data. CodeIgniter offers several
helper functions that permit you to do this. The one you will use most
commonly is:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">set_value</span><span class="p">(</span><span class="s1">'field name'</span><span class="p">)</span>
</pre></div>
</div>
<p>Open your myform.php view file and update the <strong>value</strong> in each field
using the <a class="reference internal" href="../helpers/form_helper.html#set_value" title="set_value"><code class="xref php php-func docutils literal"><span class="pre">set_value()</span></code></a> function:</p>
<p><strong>Don’t forget to include each field name in the :php:func:`set_value()`
function calls!</strong></p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">html</span><span class="o">></span>
<span class="o"><</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">title</span><span class="o">></span><span class="nx">My</span> <span class="nx">Form</span><span class="o"></</span><span class="nx">title</span><span class="o">></span>
<span class="o"></</span><span class="nx">head</span><span class="o">></span>
<span class="o"><</span><span class="nx">body</span><span class="o">></span>
<span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">validation_errors</span><span class="p">();</span> <span class="cp">?></span>
<span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">form_open</span><span class="p">(</span><span class="s1">'form'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Username<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'username'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'password'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password Confirm<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"passconf"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Email Address<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"email"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'email'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">div</span><span class="p">><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Submit"</span> <span class="p">/></</span><span class="nt">div</span><span class="p">></span>
<span class="p"></</span><span class="nt">form</span><span class="p">></span>
<span class="p"></</span><span class="nt">body</span><span class="p">></span>
<span class="p"></</span><span class="nt">html</span><span class="p">></span>
</pre></div>
</div>
<p>Now reload your page and submit the form so that it triggers an error.
Your form fields should now be re-populated</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The <a class="reference internal" href="#class-reference"><span class="std std-ref">Class Reference</span></a> section below
contains methods that permit you to re-populate <select> menus,
radio buttons, and checkboxes.</p>
</div>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p>If you use an array as the name of a form field, you
must supply it as an array to the function. Example:</p>
<div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"colors[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"<?php echo set_value('colors[]'); ?>"</span> <span class="nx">size</span><span class="o">=</span><span class="s2">"50"</span> <span class="o">/></span>
</pre></div>
</div>
</div>
<p>For more info please see the <a class="reference internal" href="#using-arrays-as-field-names"><span class="std std-ref">Using Arrays as Field Names</span></a> section below.</p>
</div>
<div class="section" id="callbacks-your-own-validation-methods">
<h3><a class="toc-backref" href="#id19">Callbacks: Your own Validation Methods</a><a class="headerlink" href="#callbacks-your-own-validation-methods" title="Permalink to this headline">¶</a></h3>
<p>The validation system supports callbacks to your own validation
methods. This permits you to extend the validation class to meet your
needs. For example, if you need to run a database query to see if the
user is choosing a unique username, you can create a callback method
that does that. Let’s create an example of this.</p>
<p>In your controller, change the “username” rule to this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="s1">'callback_username_check'</span><span class="p">);</span>
</pre></div>
</div>
<p>Then add a new method called <code class="docutils literal"><span class="pre">username_check()</span></code> to your controller.
Here’s how your controller should now look:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span>
<span class="k">class</span> <span class="nc">Form</span> <span class="k">extends</span> <span class="nx">CI_Controller</span> <span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">index</span><span class="p">()</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">helper</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'form'</span><span class="p">,</span> <span class="s1">'url'</span><span class="p">));</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">library</span><span class="p">(</span><span class="s1">'form_validation'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span> <span class="s1">'callback_username_check'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'password'</span><span class="p">,</span> <span class="s1">'Password'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">,</span> <span class="s1">'Password Confirmation'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'email'</span><span class="p">,</span> <span class="s1">'Email'</span><span class="p">,</span> <span class="s1">'required|is_unique[users.email]'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">run</span><span class="p">()</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'myform'</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'formsuccess'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">username_check</span><span class="p">(</span><span class="nv">$str</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$str</span> <span class="o">==</span> <span class="s1">'test'</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_message</span><span class="p">(</span><span class="s1">'username_check'</span><span class="p">,</span> <span class="s1">'The {field} field can not be the word "test"'</span><span class="p">);</span>
<span class="k">return</span> <span class="k">FALSE</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="k">return</span> <span class="k">TRUE</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Reload your form and submit it with the word “test” as the username. You
can see that the form field data was passed to your callback method
for you to process.</p>
<p>To invoke a callback just put the method name in a rule, with
“callback_” as the rule <strong>prefix</strong>. If you need to receive an extra
parameter in your callback method, just add it normally after the
method name between square brackets, as in: <code class="docutils literal"><span class="pre">callback_foo[bar]</span></code>,
then it will be passed as the second argument of your callback method.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You can also process the form data that is passed to your
callback and return it. If your callback returns anything other than a
boolean TRUE/FALSE it is assumed that the data is your newly processed
form data.</p>
</div>
</div>
<div class="section" id="callable-use-anything-as-a-rule">
<h3><a class="toc-backref" href="#id20">Callable: Use anything as a rule</a><a class="headerlink" href="#callable-use-anything-as-a-rule" title="Permalink to this headline">¶</a></h3>
<p>If callback rules aren’t good enough for you (for example, because they are
limited to your controller), don’t get disappointed, there’s one more way
to create custom rules: anything that <code class="docutils literal"><span class="pre">is_callable()</span></code> would return TRUE for.</p>
<p>Consider the following example:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span>
<span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">users_model</span><span class="p">,</span> <span class="s1">'valid_username'</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>The above code would use the <code class="docutils literal"><span class="pre">valid_username()</span></code> method from your
<code class="docutils literal"><span class="pre">Users_model</span></code> object.</p>
<p>This is just an example of course, and callbacks aren’t limited to models.
You can use any object/method that accepts the field value as its’ first
parameter. You can also use an anonymous function:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span>
<span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span><span class="p">,</span>
<span class="k">function</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// Check $value</span>
<span class="p">}</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>Of course, since a Callable rule by itself is not a string, it isn’t
a rule name either. That is a problem when you want to set error messages
for them. In order to get around that problem, you can put such rules as
the second element of an array, with the first one being the rule name:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span>
<span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span><span class="s1">'username_callable'</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">users_model</span><span class="p">,</span> <span class="s1">'valid_username'</span><span class="p">))</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>Anonymous function version:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span>
<span class="s1">'username'</span><span class="p">,</span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'required'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'username_callable'</span><span class="p">,</span>
<span class="k">function</span><span class="p">(</span><span class="nv">$str</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// Check validity of $str and return TRUE or FALSE</span>
<span class="p">}</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="setting-error-messages">
<span id="id2"></span><h3><a class="toc-backref" href="#id21">Setting Error Messages</a><a class="headerlink" href="#setting-error-messages" title="Permalink to this headline">¶</a></h3>
<p>All of the native error messages are located in the following language
file: <strong>system/language/english/form_validation_lang.php</strong></p>
<p>To set your own global custom message for a rule, you can either
extend/override the language file by creating your own in
<strong>application/language/english/form_validation_lang.php</strong> (read more
about this in the <a class="reference internal" href="language.html"><span class="doc">Language Class</span></a> documentation),
or use the following method:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_message</span><span class="p">(</span><span class="s1">'rule'</span><span class="p">,</span> <span class="s1">'Error Message'</span><span class="p">);</span>
</pre></div>
</div>
<p>If you need to set a custom error message for a particular field on
some particular rule, use the set_rules() method:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'field_name'</span><span class="p">,</span> <span class="s1">'Field Label'</span><span class="p">,</span> <span class="s1">'rule1|rule2|rule3'</span><span class="p">,</span>
<span class="k">array</span><span class="p">(</span><span class="s1">'rule2'</span> <span class="o">=></span> <span class="s1">'Error Message on rule2 for this field_name'</span><span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>Where rule corresponds to the name of a particular rule, and Error
Message is the text you would like displayed.</p>
<p>If you’d like to include a field’s “human” name, or the optional
parameter some rules allow for (such as max_length), you can add the
<strong>{field}</strong> and <strong>{param}</strong> tags to your message, respectively:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_message</span><span class="p">(</span><span class="s1">'min_length'</span><span class="p">,</span> <span class="s1">'{field} must have at least {param} characters.'</span><span class="p">);</span>
</pre></div>
</div>
<p>On a field with the human name Username and a rule of min_length[5], an
error would display: “Username must have at least 5 characters.”</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The old <cite>sprintf()</cite> method of using <strong>%s</strong> in your error messages
will still work, however it will override the tags above. You should
use one or the other.</p>
</div>
<p>In the callback rule example above, the error message was set by passing
the name of the method (without the “callback_” prefix):</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_message</span><span class="p">(</span><span class="s1">'username_check'</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="translating-field-names">
<span id="id3"></span><h3><a class="toc-backref" href="#id22">Translating Field Names</a><a class="headerlink" href="#translating-field-names" title="Permalink to this headline">¶</a></h3>
<p>If you would like to store the “human” name you passed to the
<code class="docutils literal"><span class="pre">set_rules()</span></code> method in a language file, and therefore make the name
able to be translated, here’s how:</p>
<p>First, prefix your “human” name with <strong>lang:</strong>, as in this example:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'first_name'</span><span class="p">,</span> <span class="s1">'lang:first_name'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
</pre></div>
</div>
<p>Then, store the name in one of your language file arrays (without the
prefix):</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$lang</span><span class="p">[</span><span class="s1">'first_name'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'First Name'</span><span class="p">;</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>If you store your array item in a language file that is not
loaded automatically by CI, you’ll need to remember to load it in your
controller using:</p>
<div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">lang</span><span class="o">-></span><span class="na">load</span><span class="p">(</span><span class="s1">'file_name'</span><span class="p">);</span>
</pre></div>
</div>
</div>
<p>See the <a class="reference internal" href="language.html"><span class="doc">Language Class</span></a> page for more info regarding
language files.</p>
</div>
<div class="section" id="changing-the-error-delimiters">
<span id="changing-delimiters"></span><h3><a class="toc-backref" href="#id23">Changing the Error Delimiters</a><a class="headerlink" href="#changing-the-error-delimiters" title="Permalink to this headline">¶</a></h3>
<p>By default, the Form Validation class adds a paragraph tag (<p>) around
each error message shown. You can either change these delimiters
globally, individually, or change the defaults in a config file.</p>
<ol class="arabic">
<li><p class="first"><strong>Changing delimiters Globally</strong>
To globally change the error delimiters, in your controller method,
just after loading the Form Validation class, add this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_error_delimiters</span><span class="p">(</span><span class="s1">'<div class="error">'</span><span class="p">,</span> <span class="s1">'</div>'</span><span class="p">);</span>
</pre></div>
</div>
<p>In this example, we’ve switched to using div tags.</p>
</li>
<li><p class="first"><strong>Changing delimiters Individually</strong>
Each of the two error generating functions shown in this tutorial can
be supplied their own delimiters as follows:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'field name'</span><span class="p">,</span> <span class="s1">'<div class="error">'</span><span class="p">,</span> <span class="s1">'</div>'</span><span class="p">);</span> <span class="cp">?></span>
</pre></div>
</div>
<p>Or:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">validation_errors</span><span class="p">(</span><span class="s1">'<div class="error">'</span><span class="p">,</span> <span class="s1">'</div>'</span><span class="p">);</span> <span class="cp">?></span>
</pre></div>
</div>
</li>
<li><p class="first"><strong>Set delimiters in a config file</strong>
You can add your error delimiters in application/config/form_validation.php as follows:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">'error_prefix'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'<div class="error_prefix">'</span><span class="p">;</span>
<span class="nv">$config</span><span class="p">[</span><span class="s1">'error_suffix'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'</div>'</span><span class="p">;</span>
</pre></div>
</div>
</li>
</ol>
</div>
<div class="section" id="showing-errors-individually">
<h3><a class="toc-backref" href="#id24">Showing Errors Individually</a><a class="headerlink" href="#showing-errors-individually" title="Permalink to this headline">¶</a></h3>
<p>If you prefer to show an error message next to each form field, rather
than as a list, you can use the <a class="reference internal" href="../helpers/form_helper.html#form_error" title="form_error"><code class="xref php php-func docutils literal"><span class="pre">form_error()</span></code></a> function.</p>
<p>Try it! Change your form so that it looks like this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">h5</span><span class="o">></span><span class="nx">Username</span><span class="o"></</span><span class="nx">h5</span><span class="o">></span>
<span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'username'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'username'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'password'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'password'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Password Confirm<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"passconf"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'passconf'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">h5</span><span class="p">></span>Email Address<span class="p"></</span><span class="nt">h5</span><span class="p">></span>
<span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'email'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"email"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s1">'email'</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
</pre></div>
</div>
<p>If there are no errors, nothing will be shown. If there is an error, the
message will appear.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p>If you use an array as the name of a form field, you
must supply it as an array to the function. Example:</p>
<div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'options[size]'</span><span class="p">);</span> <span class="cp">?></span>
<span class="p"><</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="na">name</span><span class="o">=</span><span class="s">"options[size]"</span> <span class="na">value</span><span class="o">=</span><span class="s">"</span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nx">set_value</span><span class="p">(</span><span class="s2">"options[size]"</span><span class="p">);</span> <span class="cp">?></span><span class="s">"</span> <span class="na">size</span><span class="o">=</span><span class="s">"50"</span> <span class="p">/></span>
</pre></div>
</div>
</div>
<p>For more info please see the <a class="reference internal" href="#using-arrays-as-field-names"><span class="std std-ref">Using Arrays as Field Names</span></a> section below.</p>
</div>
<div class="section" id="validating-an-array-other-than-post">
<h3><a class="toc-backref" href="#id25">Validating an Array (other than $_POST)</a><a class="headerlink" href="#validating-an-array-other-than-post" title="Permalink to this headline">¶</a></h3>
<p>Sometimes you may want to validate an array that does not originate from <code class="docutils literal"><span class="pre">$_POST</span></code> data.</p>
<p>In this case, you can specify the array to be validated:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'username'</span> <span class="o">=></span> <span class="s1">'johndoe'</span><span class="p">,</span>
<span class="s1">'password'</span> <span class="o">=></span> <span class="s1">'mypassword'</span><span class="p">,</span>
<span class="s1">'passconf'</span> <span class="o">=></span> <span class="s1">'mypassword'</span>
<span class="p">);</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_data</span><span class="p">(</span><span class="nv">$data</span><span class="p">);</span>
</pre></div>
</div>
<p>Creating validation rules, running the validation, and retrieving error
messages works the same whether you are validating <code class="docutils literal"><span class="pre">$_POST</span></code> data or
another array of your choice.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">You have to call the <code class="docutils literal"><span class="pre">set_data()</span></code> method <em>before</em> defining
any validation rules.</p>
</div>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">If you want to validate more than one array during a single
execution, then you should call the <code class="docutils literal"><span class="pre">reset_validation()</span></code> method
before setting up rules and validating the new array.</p>
</div>
<p>For more info please see the <a class="reference internal" href="#class-reference"><span class="std std-ref">Class Reference</span></a> section below.</p>
</div>
</div>
<div class="section" id="saving-sets-of-validation-rules-to-a-config-file">
<span id="saving-groups"></span><h2><a class="toc-backref" href="#id26">Saving Sets of Validation Rules to a Config File</a><a class="headerlink" href="#saving-sets-of-validation-rules-to-a-config-file" title="Permalink to this headline">¶</a></h2>
<p>A nice feature of the Form Validation class is that it permits you to
store all your validation rules for your entire application in a config
file. You can organize these rules into “groups”. These groups can
either be loaded automatically when a matching controller/method is
called, or you can manually call each set as needed.</p>
<div class="section" id="how-to-save-your-rules">
<h3><a class="toc-backref" href="#id27">How to save your rules</a><a class="headerlink" href="#how-to-save-your-rules" title="Permalink to this headline">¶</a></h3>
<p>To store your validation rules, simply create a file named
form_validation.php in your application/config/ folder. In that file
you will place an array named $config with your rules. As shown earlier,
the validation array will have this prototype:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'username'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'password'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'passconf'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password Confirmation'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'email'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Email'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>Your validation rule file will be loaded automatically and used when you
call the <code class="docutils literal"><span class="pre">run()</span></code> method.</p>
<p>Please note that you MUST name your <code class="docutils literal"><span class="pre">$config</span></code> array.</p>
</div>
<div class="section" id="creating-sets-of-rules">
<h3><a class="toc-backref" href="#id28">Creating Sets of Rules</a><a class="headerlink" href="#creating-sets-of-rules" title="Permalink to this headline">¶</a></h3>
<p>In order to organize your rules into “sets” requires that you place them
into “sub arrays”. Consider the following example, showing two sets of
rules. We’ve arbitrarily called these two rules “signup” and “email”.
You can name your rules anything you want:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'signup'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'username'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'password'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'passconf'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password Confirmation'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'email'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Email'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">)</span>
<span class="p">),</span>
<span class="s1">'email'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'emailaddress'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'EmailAddress'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required|valid_email'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'name'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Name'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required|alpha'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'title'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Title'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'message'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'MessageBody'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
</div>
<div class="section" id="calling-a-specific-rule-group">
<h3><a class="toc-backref" href="#id29">Calling a Specific Rule Group</a><a class="headerlink" href="#calling-a-specific-rule-group" title="Permalink to this headline">¶</a></h3>
<p>In order to call a specific group, you will pass its name to the <code class="docutils literal"><span class="pre">run()</span></code>
method. For example, to call the signup rule you will do this:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">run</span><span class="p">(</span><span class="s1">'signup'</span><span class="p">)</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'myform'</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'formsuccess'</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="associating-a-controller-method-with-a-rule-group">
<h3><a class="toc-backref" href="#id30">Associating a Controller Method with a Rule Group</a><a class="headerlink" href="#associating-a-controller-method-with-a-rule-group" title="Permalink to this headline">¶</a></h3>
<p>An alternate (and more automatic) method of calling a rule group is to
name it according to the controller class/method you intend to use it
with. For example, let’s say you have a controller named Member and a
method named signup. Here’s what your class might look like:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span>
<span class="k">class</span> <span class="nc">Member</span> <span class="k">extends</span> <span class="nx">CI_Controller</span> <span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">signup</span><span class="p">()</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">library</span><span class="p">(</span><span class="s1">'form_validation'</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">run</span><span class="p">()</span> <span class="o">==</span> <span class="k">FALSE</span><span class="p">)</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'myform'</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="nv">$this</span><span class="o">-></span><span class="na">load</span><span class="o">-></span><span class="na">view</span><span class="p">(</span><span class="s1">'formsuccess'</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In your validation config file, you will name your rule group
member/signup:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
<span class="s1">'member/signup'</span> <span class="o">=></span> <span class="k">array</span><span class="p">(</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'username'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Username'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'password'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Password'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'passconf'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'PasswordConfirmation'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">),</span>
<span class="k">array</span><span class="p">(</span>
<span class="s1">'field'</span> <span class="o">=></span> <span class="s1">'email'</span><span class="p">,</span>
<span class="s1">'label'</span> <span class="o">=></span> <span class="s1">'Email'</span><span class="p">,</span>
<span class="s1">'rules'</span> <span class="o">=></span> <span class="s1">'required'</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">);</span>
</pre></div>
</div>
<p>When a rule group is named identically to a controller class/method it
will be used automatically when the <code class="docutils literal"><span class="pre">run()</span></code> method is invoked from that
class/method.</p>
</div>
</div>
<div class="section" id="using-arrays-as-field-names">
<span id="id4"></span><h2><a class="toc-backref" href="#id31">Using Arrays as Field Names</a><a class="headerlink" href="#using-arrays-as-field-names" title="Permalink to this headline">¶</a></h2>
<p>The Form Validation class supports the use of arrays as field names.
Consider this example:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">""</span> <span class="nx">size</span><span class="o">=</span><span class="s2">"50"</span> <span class="o">/></span>
</pre></div>
</div>
<p>If you do use an array as a field name, you must use the EXACT array
name in the <a class="reference internal" href="#helper-functions"><span class="std std-ref">Helper Functions</span></a> that require the
field name, and as your Validation Rule field name.</p>
<p>For example, to set a rule for the above field you would use:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">set_rules</span><span class="p">(</span><span class="s1">'options[]'</span><span class="p">,</span> <span class="s1">'Options'</span><span class="p">,</span> <span class="s1">'required'</span><span class="p">);</span>
</pre></div>
</div>
<p>Or, to show an error for the above field you would use:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'options[]'</span><span class="p">);</span> <span class="cp">?></span>
</pre></div>
</div>
<p>Or to re-populate the field you would use:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"<?php echo set_value('options[]'); ?>"</span> <span class="nx">size</span><span class="o">=</span><span class="s2">"50"</span> <span class="o">/></span>
</pre></div>
</div>
<p>You can use multidimensional arrays as field names as well. For example:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[size]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">""</span> <span class="nx">size</span><span class="o">=</span><span class="s2">"50"</span> <span class="o">/></span>
</pre></div>
</div>
<p>Or even:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"sports[nba][basketball]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">""</span> <span class="nx">size</span><span class="o">=</span><span class="s2">"50"</span> <span class="o">/></span>
</pre></div>
</div>
<p>As with our first example, you must use the exact array name in the
helper functions:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'sports[nba][basketball]'</span><span class="p">);</span> <span class="cp">?></span>
</pre></div>
</div>
<p>If you are using checkboxes (or other fields) that have multiple
options, don’t forget to leave an empty bracket after each option, so
that all selections will be added to the POST array:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"red"</span> <span class="o">/></span>
<span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"blue"</span> <span class="o">/></span>
<span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"green"</span> <span class="o">/></span>
</pre></div>
</div>
<p>Or if you use a multidimensional array:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[color][]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"red"</span> <span class="o">/></span>
<span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[color][]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"blue"</span> <span class="o">/></span>
<span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"checkbox"</span> <span class="nx">name</span><span class="o">=</span><span class="s2">"options[color][]"</span> <span class="nx">value</span><span class="o">=</span><span class="s2">"green"</span> <span class="o">/></span>
</pre></div>
</div>
<p>When you use a helper function you’ll include the bracket as well:</p>
<div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o"><?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nx">form_error</span><span class="p">(</span><span class="s1">'options[color][]'</span><span class="p">);</span> <span class="cp">?></span>
</pre></div>
</div>
</div>
<div class="section" id="rule-reference">
<h2><a class="toc-backref" href="#id32">Rule Reference</a><a class="headerlink" href="#rule-reference" title="Permalink to this headline">¶</a></h2>
<p>The following is a list of all the native rules that are available to
use:</p>
<table border="1" class="docutils">
<colgroup>
<col width="16%" />
<col width="7%" />
<col width="61%" />
<col width="16%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Rule</th>
<th class="head">Parameter</th>
<th class="head">Description</th>
<th class="head">Example</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><strong>required</strong></td>
<td>No</td>
<td>Returns FALSE if the form element is empty.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>matches</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element does not match the one in the parameter.</td>
<td>matches[form_item]</td>
</tr>
<tr class="row-even"><td><strong>regex_match</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element does not match the regular expression.</td>
<td>regex_match[/regex/]</td>
</tr>
<tr class="row-odd"><td><strong>differs</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element does not differ from the one in the parameter.</td>
<td>differs[form_item]</td>
</tr>
<tr class="row-even"><td><strong>is_unique</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is not unique to the table and field name in the
parameter. Note: This rule requires <a class="reference internal" href="../database/query_builder.html"><span class="doc">Query Builder</span></a> to be
enabled in order to work.</td>
<td>is_unique[table.field]</td>
</tr>
<tr class="row-odd"><td><strong>min_length</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is shorter than the parameter value.</td>
<td>min_length[3]</td>
</tr>
<tr class="row-even"><td><strong>max_length</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is longer than the parameter value.</td>
<td>max_length[12]</td>
</tr>
<tr class="row-odd"><td><strong>exact_length</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is not exactly the parameter value.</td>
<td>exact_length[8]</td>
</tr>
<tr class="row-even"><td><strong>greater_than</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is less than or equal to the parameter value or not
numeric.</td>
<td>greater_than[8]</td>
</tr>
<tr class="row-odd"><td><strong>greater_than_equal_to</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is less than the parameter value,
or not numeric.</td>
<td>greater_than_equal_to[8]</td>
</tr>
<tr class="row-even"><td><strong>less_than</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is greater than or equal to the parameter value or
not numeric.</td>
<td>less_than[8]</td>
</tr>
<tr class="row-odd"><td><strong>less_than_equal_to</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is greater than the parameter value,
or not numeric.</td>
<td>less_than_equal_to[8]</td>
</tr>
<tr class="row-even"><td><strong>in_list</strong></td>
<td>Yes</td>
<td>Returns FALSE if the form element is not within a predetermined list.</td>
<td>in_list[red,blue,green]</td>
</tr>
<tr class="row-odd"><td><strong>alpha</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than alphabetical characters.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>alpha_numeric</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than alpha-numeric characters.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>alpha_numeric_spaces</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than alpha-numeric characters
or spaces. Should be used after trim to avoid spaces at the beginning or end.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>alpha_dash</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than alpha-numeric characters,
underscores or dashes.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>numeric</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than numeric characters.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>integer</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than an integer.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>decimal</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than a decimal number.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>is_natural</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than a natural number:
0, 1, 2, 3, etc.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>is_natural_no_zero</strong></td>
<td>No</td>
<td>Returns FALSE if the form element contains anything other than a natural
number, but not zero: 1, 2, 3, etc.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>valid_url</strong></td>
<td>No</td>
<td>Returns FALSE if the form element does not contain a valid URL.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>valid_email</strong></td>
<td>No</td>
<td>Returns FALSE if the form element does not contain a valid email address.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>valid_emails</strong></td>
<td>No</td>
<td>Returns FALSE if any value provided in a comma separated list is not a valid email.</td>
<td> </td>
</tr>
<tr class="row-odd"><td><strong>valid_ip</strong></td>
<td>Yes</td>
<td>Returns FALSE if the supplied IP address is not valid.
Accepts an optional parameter of ‘ipv4’ or ‘ipv6’ to specify an IP format.</td>
<td> </td>
</tr>
<tr class="row-even"><td><strong>valid_base64</strong></td>
<td>No</td>
<td>Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td>
<td> </td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>These rules can also be called as discrete methods. For
example:</p>
<div class="last highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-></span><span class="na">form_validation</span><span class="o">-></span><span class="na">required</span><span class="p">(</span><span class="nv">$string</span><span class="p">);</span>
</pre></div>
</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">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).</p>
</div>
</div>
<div class="section" id="prepping-reference">
<h2><a class="toc-backref" href="#id33">Prepping Reference</a><a class="headerlink" href="#prepping-reference" title="Permalink to this headline">¶</a></h2>
<p>The following is a list of all the prepping methods that are available
to use:</p>
<table border="1" class="docutils">
<colgroup>
<col width="14%" />
<col width="6%" />
<col width="79%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Name</th>
<th class="head">Parameter</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><strong>prep_for_form</strong></td>
<td>No</td>
<td>DEPRECATED: Converts special characters so that HTML data can be shown in a form field without breaking it.</td>
</tr>
<tr class="row-odd"><td><strong>prep_url</strong></td>
<td>No</td>
<td>Adds “http://” to URLs if missing.</td>
</tr>
<tr class="row-even"><td><strong>strip_image_tags</strong></td>
<td>No</td>
<td>Strips the HTML from image tags leaving the raw URL.</td>
</tr>
<tr class="row-odd"><td><strong>encode_php_tags</strong></td>
<td>No</td>
<td>Converts PHP tags to entities.</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You can also use any native PHP functions that permits one
parameter, like <code class="docutils literal"><span class="pre">trim()</span></code>, <code class="docutils literal"><span class="pre">htmlspecialchars()</span></code>, <code class="docutils literal"><span class="pre">urldecode()</span></code>,
etc.</p>
</div>
</div>
<div class="section" id="class-reference">
<span id="id5"></span><h2><a class="toc-backref" href="#id34">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="CI_Form_validation">
<em class="property">class </em><code class="descname">CI_Form_validation</code><a class="headerlink" href="#CI_Form_validation" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="CI_Form_validation::set_rules">
<code class="descname">set_rules</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$label = ''</em><span class="optional">[</span>, <em>$rules = ''</em><span class="optional">[</span>, <em>$errors = array()</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::set_rules" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$field</strong> (<em>string</em>) – Field name</li>
<li><strong>$label</strong> (<em>string</em>) – Field label</li>
<li><strong>$rules</strong> (<em>mixed</em>) – Validation rules, as a string list separated by a pipe “|”, or as an array or rules</li>
<li><strong>$errors</strong> (<em>array</em>) – A list of custom error messages</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Form_validation instance (method chaining)</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Form_validation</p>
</td>
</tr>
</tbody>
</table>
<p>Permits you to set validation rules, as described in the tutorial
sections above:</p>
<ul class="simple">
<li><a class="reference internal" href="#setting-validation-rules"><span class="std std-ref">Setting Validation Rules</span></a></li>
<li><a class="reference internal" href="#saving-groups"><span class="std std-ref">Saving Sets of Validation Rules to a Config File</span></a></li>
</ul>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::run">
<code class="descname">run</code><span class="sig-paren">(</span><span class="optional">[</span><em>$group = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::run" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$group</strong> (<em>string</em>) – The name of the validation group to run</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE if validation failed</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
<p>Runs the validation routines. Returns boolean TRUE on success and FALSE
on failure. You can optionally pass the name of the validation group via
the method, as described in: <a class="reference internal" href="#saving-groups"><span class="std std-ref">Saving Sets of Validation Rules to a Config File</span></a></p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::set_message">
<code class="descname">set_message</code><span class="sig-paren">(</span><em>$lang</em><span class="optional">[</span>, <em>$val = ''</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::set_message" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$lang</strong> (<em>string</em>) – The rule the message is for</li>
<li><strong>$val</strong> (<em>string</em>) – The message</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Form_validation instance (method chaining)</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Form_validation</p>
</td>
</tr>
</tbody>
</table>
<p>Permits you to set custom error messages. See <a class="reference internal" href="#setting-error-messages"><span class="std std-ref">Setting Error Messages</span></a></p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::set_error_delimiters">
<code class="descname">set_error_delimiters</code><span class="sig-paren">(</span><span class="optional">[</span><em>$prefix = '<p>'</em><span class="optional">[</span>, <em>$suffix = '</p>'</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::set_error_delimiters" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$prefix</strong> (<em>string</em>) – Error message prefix</li>
<li><strong>$suffix</strong> (<em>string</em>) – Error message suffix</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Form_validation instance (method chaining)</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Form_validation</p>
</td>
</tr>
</tbody>
</table>
<p>Sets the default prefix and suffix for error messages.</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::set_data">
<code class="descname">set_data</code><span class="sig-paren">(</span><em>$data</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::set_data" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$data</strong> (<em>array</em>) – Array of data validate</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Form_validation instance (method chaining)</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Form_validation</p>
</td>
</tr>
</tbody>
</table>
<p>Permits you to set an array for validation, instead of using the default
<code class="docutils literal"><span class="pre">$_POST</span></code> array.</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::reset_validation">
<code class="descname">reset_validation</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::reset_validation" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">CI_Form_validation instance (method chaining)</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">CI_Form_validation</td>
</tr>
</tbody>
</table>
<p>Permits you to reset the validation when you validate more than one array.
This method should be called before validating each new array.</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::error_array">
<code class="descname">error_array</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::error_array" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Array of error messages</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">array</td>
</tr>
</tbody>
</table>
<p>Returns the error messages as an array.</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::error_string">
<code class="descname">error_string</code><span class="sig-paren">(</span><span class="optional">[</span><em>$prefix = ''</em><span class="optional">[</span>, <em>$suffix = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::error_string" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$prefix</strong> (<em>string</em>) – Error message prefix</li>
<li><strong>$suffix</strong> (<em>string</em>) – Error message suffix</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Error messages as a string</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
</td>
</tr>
</tbody>
</table>
<p>Returns all error messages (as returned from error_array()) formatted as a
string and separated by a newline character.</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::error">
<code class="descname">error</code><span class="sig-paren">(</span><em>$field</em><span class="optional">[</span>, <em>$prefix = ''</em><span class="optional">[</span>, <em>$suffix = ''</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::error" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$field</strong> (<em>string</em>) – Field name</li>
<li><strong>$prefix</strong> (<em>string</em>) – Optional prefix</li>
<li><strong>$suffix</strong> (<em>string</em>) – Optional suffix</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Error message string</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
</td>
</tr>
</tbody>
</table>
<p>Returns the error message for a specific field, optionally adding a
prefix and/or suffix to it (usually HTML tags).</p>
</dd></dl>
<dl class="method">
<dt id="CI_Form_validation::has_rule">
<code class="descname">has_rule</code><span class="sig-paren">(</span><em>$field</em><span class="sig-paren">)</span><a class="headerlink" href="#CI_Form_validation::has_rule" title="Permalink to this definition">¶</a></dt>
<dd><table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>$field</strong> (<em>string</em>) – Field name</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE if the field has rules set, FALSE if not</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
</td>
</tr>
</tbody>
</table>
<p>Checks to see if there is a rule set for the specified field.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="helper-reference">
<span id="helper-functions"></span><h2><a class="toc-backref" href="#id35">Helper Reference</a><a class="headerlink" href="#helper-reference" title="Permalink to this headline">¶</a></h2>
<p>Please refer to the <a class="reference internal" href="../helpers/form_helper.html"><span class="doc">Form Helper</span></a> manual for
the following functions:</p>
<ul class="simple">
<li><a class="reference internal" href="../helpers/form_helper.html#form_error" title="form_error"><code class="xref php php-func docutils literal"><span class="pre">form_error()</span></code></a></li>
<li><a class="reference internal" href="../helpers/form_helper.html#validation_errors" title="validation_errors"><code class="xref php php-func docutils literal"><span class="pre">validation_errors()</span></code></a></li>
<li><a class="reference internal" href="../helpers/form_helper.html#set_value" title="set_value"><code class="xref php php-func docutils literal"><span class="pre">set_value()</span></code></a></li>
<li><a class="reference internal" href="../helpers/form_helper.html#set_select" title="set_select"><code class="xref php php-func docutils literal"><span class="pre">set_select()</span></code></a></li>
<li><a class="reference internal" href="../helpers/form_helper.html#set_checkbox" title="set_checkbox"><code class="xref php php-func docutils literal"><span class="pre">set_checkbox()</span></code></a></li>
<li><a class="reference internal" href="../helpers/form_helper.html#set_radio" title="set_radio"><code class="xref php php-func docutils literal"><span class="pre">set_radio()</span></code></a></li>
</ul>
<p>Note that these are procedural functions, so they <strong>do not</strong> require you
to prepend them with <code class="docutils literal"><span class="pre">$this->form_validation</span></code>.</p>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="ftp.html" class="btn btn-neutral float-right" title="FTP Class">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="file_uploading.html" class="btn btn-neutral" title="File Uploading Class"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2014 - 2018, British Columbia Institute of Technology.
Last updated on Jan 13, 2018.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'3.1.7',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: false
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|