blob: ede1913e02673cdf443f073732afe00a56bdd249 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3<head>
4
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<title>Form Validation : CodeIgniter User Guide</title>
7
8<style type='text/css' media='all'>@import url('../userguide.css');</style>
9<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
10
11<script type="text/javascript" src="../nav/nav.js"></script>
12<script type="text/javascript" src="../nav/prototype.lite.js"></script>
13<script type="text/javascript" src="../nav/moo.fx.js"></script>
14<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
15
16<meta http-equiv='expires' content='-1' />
17<meta http-equiv= 'pragma' content='no-cache' />
18<meta name='robots' content='all' />
19<meta name='author' content='ExpressionEngine Dev Team' />
20<meta name='description' content='CodeIgniter User Guide' />
21</head>
22<body>
23
24<!-- START NAVIGATION -->
25<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
26<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
27<div id="masthead">
28<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
29<tr>
Derek Jonesb8c038a2011-08-20 08:57:14 -050030<td><h1>CodeIgniter User Guide Version 2.0.3</h1></td>
Derek Allard2067d1a2008-11-13 22:59:24 +000031<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
32</tr>
33</table>
34</div>
35<!-- END NAVIGATION -->
36
37
38<!-- START BREADCRUMB -->
39<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
40<tr>
41<td id="breadcrumb">
42<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
43<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
44Form Validation
45</td>
46<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
47</tr>
48</table>
49<!-- END BREADCRUMB -->
50
51<br clear="all" />
52
53
54<!-- START CONTENT -->
55<div id="content">
56
57<h1>Form Validation</h1>
58
59<p>CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you'll write.</p>
60
Derek Allard2067d1a2008-11-13 22:59:24 +000061<ul>
62<li><a href="#overview">Overview</a></li>
63<li><a href="#tutorial">Form Validation Tutorial</a>
64
65 <ul>
66 <li><a href="#theform">The Form</a></li>
67 <li><a href="#thesuccesspage">The Success Page</a></li>
68 <li><a href="#thecontroller">The Controller</a></li>
69 <li><a href="#validationrules">Setting Validation Rules</a></li>
70 <li><a href="#validationrulesasarray">Setting Validation Rules Using an Array</a></li>
71 <li><a href="#cascadingrules">Cascading Rules</a></li>
72 <li><a href="#preppingdata">Prepping Data</a></li>
73 <li><a href="#repopulatingform">Re-populating the Form</a></li>
74 <li><a href="#callbacks">Callbacks</a></li>
75 <li><a href="#settingerrors">Setting Error Messages</a></li>
76 <li><a href="#errordelimiters">Changing the Error Delimiters</a></li>
77 <li><a href="#translatingfn">Translating Field Names</a></li>
78 <li><a href="#individualerrors">Showing Errors Individually</a></li>
79 <li><a href="#savingtoconfig">Saving Sets of Validation Rules to a Config File</a></li>
80 <li><a href="#arraysasfields">Using Arrays as Field Names</a></li>
81 </ul>
82</li>
83<li><a href="#rulereference">Rule Reference</a></li>
84<li><a href="#preppingreference">Prepping Reference</a></li>
85<li><a href="#functionreference">Function Reference</a></li>
86<li><a href="#helperreference">Helper Reference</a></li>
87
88</ul>
89
90
91
92
93
94
95<p>&nbsp;</p>
96
97<a name="overview"></a>
98<h1>Overview</h1>
99
100
101<p>Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:</p>
102
103<ol>
104<li>A form is displayed.</li>
105<li>You fill it in and submit it.</li>
Barry Mienydd671972010-10-04 16:33:58 +0200106<li>If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data
Derek Allard2067d1a2008-11-13 22:59:24 +0000107along with an error message describing the problem.</li>
108<li>This process continues until you have submitted a valid form.</li>
109</ol>
110
111<p>On the receiving end, the script must:</p>
112
113<ol>
114<li>Check for required data.</li>
115<li>Verify that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted
Derek Jones37f4b9c2011-07-01 17:56:50 -0500116it must be validated to contain only permitted characters. It must be of a minimum length,
Derek Allard2067d1a2008-11-13 22:59:24 +0000117and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.</li>
118<li>Sanitize the data for security.</li>
Derek Jones37f4b9c2011-07-01 17:56:50 -0500119<li>Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)</li>
Derek Allard2067d1a2008-11-13 22:59:24 +0000120<li>Prep the data for insertion in the database.</li>
121</ol>
122
123
124<p>Although there is nothing terribly complex about the above process, it usually requires a significant
125amount of code, and to display error messages, various control structures are usually placed within the form HTML.
126Form validation, while simple to create, is generally very messy and tedious to implement.</p>
127
128<p>&nbsp;</p>
129
130
131<a name="tutorial"></a>
132<h1>Form Validation Tutorial</h1>
133
134<p>What follows is a "hands on" tutorial for implementing CodeIgniters Form Validation.</p>
135
136
137<p>In order to implement form validation you'll need three things:</p>
138
139<ol>
140<li>A <a href="../general/views.html">View</a> file containing a form.</li>
141<li>A View file containing a "success" message to be displayed upon successful submission.</li>
142<li>A <a href="../general/controllers.html">controller</a> function to receive and process the submitted data.</li>
143</ol>
144
145<p>Let's create those three things, using a member sign-up form as the example.</p>
146
147
148
149<a name="theform"></a>
150
151<h2>The Form</h2>
152
Derek Jones37f4b9c2011-07-01 17:56:50 -0500153<p>Using a text editor, create a form called <dfn>myform.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
Derek Allard2067d1a2008-11-13 22:59:24 +0000154folder:</p>
155
156
157<textarea class="textarea" style="width:100%" cols="50" rows="30">&lt;html>
158&lt;head>
159&lt;title>My Form&lt;/title>
160&lt;/head>
161&lt;body>
162
163&lt;?php echo validation_errors(); ?>
164
165&lt;?php echo form_open('form'); ?>
166
167&lt;h5>Username&lt;/h5>
168&lt;input type="text" name="username" value="" size="50" />
169
170&lt;h5>Password&lt;/h5>
171&lt;input type="text" name="password" value="" size="50" />
172
173&lt;h5>Password Confirm&lt;/h5>
174&lt;input type="text" name="passconf" value="" size="50" />
175
176&lt;h5>Email Address&lt;/h5>
177&lt;input type="text" name="email" value="" size="50" />
178
179&lt;div>&lt;input type="submit" value="Submit" />&lt;/div>
180
181&lt;/form>
182
183&lt;/body>
184&lt;/html>
185</textarea>
186
187
188
189
190<a name="thesuccesspage"></a>
191<h2>The Success Page</h2>
192
193
Derek Jones37f4b9c2011-07-01 17:56:50 -0500194<p>Using a text editor, create a form called <dfn>formsuccess.php</dfn>. In it, place this code and save it to your <samp>applications/views/</samp>
Derek Allard2067d1a2008-11-13 22:59:24 +0000195folder:</p>
196
197
198<textarea class="textarea" style="width:100%" cols="50" rows="14">
199&lt;html>
200&lt;head>
201&lt;title>My Form&lt;/title>
202&lt;/head>
203&lt;body>
204
205&lt;h3>Your form was successfully submitted!&lt;/h3>
206
207&lt;p>&lt;?php echo anchor('form', 'Try it again!'); ?>&lt;/p>
208
209&lt;/body>
210&lt;/html>
211</textarea>
212
213
214
215<a name="thecontroller"></a>
216<h2>The Controller</h2>
217
Derek Jones37f4b9c2011-07-01 17:56:50 -0500218<p>Using a text editor, create a controller called <dfn>form.php</dfn>. In it, place this code and save it to your <samp>applications/controllers/</samp>
Derek Allard2067d1a2008-11-13 22:59:24 +0000219folder:</p>
220
221
222<textarea class="textarea" style="width:100%" cols="50" rows="21">&lt;?php
223
Greg Aker16fcb2e2010-11-09 13:53:07 -0600224class Form extends CI_Controller {
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 function index()
227 {
228 $this->load->helper(array('form', 'url'));
Barry Mienydd671972010-10-04 16:33:58 +0200229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 $this->load->library('form_validation');
Barry Mienydd671972010-10-04 16:33:58 +0200231
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 if ($this->form_validation->run() == FALSE)
233 {
234 $this->load->view('myform');
235 }
236 else
237 {
238 $this->load->view('formsuccess');
239 }
240 }
241}
242?></textarea>
243
244
245<h2>Try it!</h2>
246
247<p>To try your form, visit your site using a URL similar to this one:</p>
248
249<code>example.com/index.php/<var>form</var>/</code>
250
Derek Jones37f4b9c2011-07-01 17:56:50 -0500251<p><dfn>If you submit the form you should simply see the form reload. That's because you haven't set up any validation
Derek Allard2067d1a2008-11-13 22:59:24 +0000252rules yet.</dfn></p>
253
Derek Jones37f4b9c2011-07-01 17:56:50 -0500254<p><strong>Since you haven't told the Form Validation class to validate anything yet, it returns <kbd>FALSE</kbd> (boolean false) by default. The <samp>run()</samp>
Derek Allard2067d1a2008-11-13 22:59:24 +0000255function only returns <kbd>TRUE</kbd> if it has successfully applied your rules without any of them failing.</strong></p>
256
257
258<h2>Explanation</h2>
259
260<p>You'll notice several things about the above pages:</p>
261
262<p>The <dfn>form</dfn> (myform.php) is a standard web form with a couple exceptions:</p>
263
264<ol>
265<li>It uses a <dfn>form helper</dfn> to create the form opening.
Derek Jones37f4b9c2011-07-01 17:56:50 -0500266Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper
267is 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.</li>
Derek Allard2067d1a2008-11-13 22:59:24 +0000268
269<li>At the top of the form you'll notice the following function call:
270<code>&lt;?php echo validation_errors(); ?&gt;</code>
271
272<p>This function will return any error messages sent back by the validator. If there are no messages it returns an empty string.</p>
273</li>
274</ol>
275
276<p>The <dfn>controller</dfn> (form.php) has one function: <dfn>index()</dfn>. This function initializes the validation class and
277loads the <var>form helper</var> and <var>URL helper</var> used by your view files. It also <samp>runs</samp>
278the validation routine. Based on
279whether the validation was successful it either presents the form or the success page.</p>
280
281
282
283
284<a name="validationrules"></a>
285
286<h2>Setting Validation Rules</h2>
287
288<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
289at the same time. To set validation rules you will use the <dfn>set_rules()</dfn> function:</p>
290
291<code>$this->form_validation->set_rules();</code>
292
293<p>The above function takes <strong>three</strong> parameters as input:</p>
294
295<ol>
296 <li>The field name - the exact name you've given the form field.</li>
297 <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". <strong>Note:</strong> If you would like the field name to be stored in a language file, please see <a href="#translatingfn">Translating Field Names</a>.</li>
298 <li>The validation rules for this form field.</li>
299</ol>
300
301
302<p><br />Here is an example. In your <dfn>controller</dfn> (form.php), add this code just below the validation initialization function:</p>
303
304<code>
305$this->form_validation->set_rules('username', 'Username', 'required');<br />
306$this->form_validation->set_rules('password', 'Password', 'required');<br />
307$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br />
308$this->form_validation->set_rules('email', 'Email', 'required');<br />
309</code>
310
311<p>Your controller should now look like this:</p>
312
Derek Allard4b6d4932008-12-07 17:04:56 +0000313<textarea class="textarea" style="width:100%" cols="50" rows="28">&lt;?php
Derek Allard2067d1a2008-11-13 22:59:24 +0000314
Greg Aker16fcb2e2010-11-09 13:53:07 -0600315class Form extends CI_Controller {
Barry Mienydd671972010-10-04 16:33:58 +0200316
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 function index()
318 {
319 $this->load->helper(array('form', 'url'));
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 $this->load->library('form_validation');
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 $this->form_validation->set_rules('username', 'Username', 'required');
324 $this->form_validation->set_rules('password', 'Password', 'required');
325 $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
326 $this->form_validation->set_rules('email', 'Email', 'required');
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 if ($this->form_validation->run() == FALSE)
329 {
330 $this->load->view('myform');
331 }
332 else
333 {
334 $this->load->view('formsuccess');
335 }
336 }
337}
338?></textarea>
339
340<p><dfn>Now submit the form with the fields blank and you should see the error messages.
341If you submit the form with all the fields populated you'll see your success page.</dfn></p>
342
343<p class="important"><strong>Note:</strong> The form fields are not yet being re-populated with the data when
Derek Jones37f4b9c2011-07-01 17:56:50 -0500344there is an error. We'll get to that shortly.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000345
346
347
348
349<a name="validationrulesasarray"></a>
350<h2>Setting Rules Using an Array</h2>
351
352<p>Before moving on it should be noted that the rule setting function can be passed an array if you prefer to set all your rules in one action.
353If you use this approach you must name your array keys as indicated:</p>
354
355<code>
356$config = array(<br />
357&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
358&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field'&nbsp;&nbsp;&nbsp;=> 'username', <br />
359&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label'&nbsp;&nbsp;&nbsp;=> 'Username', <br />
360&nbsp;&nbsp;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p;&nbsp;&nbsp;=> 'Email', <br />
375&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rules'&nbsp;&nbsp;&nbsp;=> 'required'<br />
376&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br />
377&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
378<br />
379$this->form_validation->set_rules($config);
380</code>
381
382
383
384
385
386
387<a name="cascadingrules"></a>
388<h2>Cascading Rules</h2>
389
Derek Jones37f4b9c2011-07-01 17:56:50 -0500390<p>CodeIgniter lets you pipe multiple rules together. Let's try it. Change your rules in the third parameter of rule setting function, like this:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000391
392<code>
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100393$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[users.username]');<br />
Derek Allard2067d1a2008-11-13 22:59:24 +0000394$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');<br />
395$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');<br />
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100396$this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');<br />
Derek Allard2067d1a2008-11-13 22:59:24 +0000397</code>
398
399<p>The above code sets the following rules:</p>
400
401<ol>
402<li>The username field be no shorter than 5 characters and no longer than 12.</li>
403<li>The password field must match the password confirmation field.</li>
404<li>The email field must contain a valid email address.</li>
405</ol>
406
407<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.
408There are numerous rules available which you can read about in the validation reference.</p>
409
410
411
412<a name="preppingdata"></a>
413<h2>Prepping Data</h2>
414
415<p>In addition to the validation functions like the ones we used above, you can also prep your data in various ways.
416For example, you can set up rules like this:</p>
417
418<code>
419$this->form_validation->set_rules('username', 'Username', '<kbd>trim</kbd>|required|min_length[5]|max_length[12]|<kbd>xss_clean</kbd>');<br />
420$this->form_validation->set_rules('password', 'Password', '<kbd>trim</kbd>|required|matches[passconf]|<kbd>md5</kbd>');<br />
421$this->form_validation->set_rules('passconf', 'Password Confirmation', '<kbd>trim</kbd>|required');<br />
422$this->form_validation->set_rules('email', 'Email', '<kbd>trim</kbd>|required|valid_email');<br />
423</code>
424
425
426<p>In the above example, we are "trimming" the fields, converting the password to MD5, and running the username through
427the "xss_clean" function, which removes malicious data.</p>
428
429<p><strong>Any native PHP function that accepts one parameter can be used as a rule, like <dfn>htmlspecialchars</dfn>,
Derek Jones37f4b9c2011-07-01 17:56:50 -0500430<dfn>trim</dfn>, <dfn>MD5</dfn>, etc.</strong></p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000431
432<p><strong>Note:</strong> You will generally want to use the prepping functions <strong>after</strong>
433the validation rules so if there is an error, the original data will be shown in the form.</p>
434
435
436
437
438<a name="repopulatingform"></a>
439<h2>Re-populating the form</h2>
440
Derek Jones37f4b9c2011-07-01 17:56:50 -0500441<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
Derek Allard2067d1a2008-11-13 22:59:24 +0000442that permit you to do this. The one you will use most commonly is:</p>
443
444<code>set_value('field name')</code>
445
446
447<p>Open your <dfn>myform.php</dfn> view file and update the <strong>value</strong> in each field using the <dfn>set_value()</dfn> function:</p>
448
Derek Allard028cbb52010-01-17 08:07:49 +0000449<p><strong>Don't forget to include each field name in the <dfn>set_value()</dfn> functions!</strong></p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000450
451
452<textarea class="textarea" style="width:100%" cols="50" rows="30">
453&lt;html>
454&lt;head>
455&lt;title>My Form&lt;/title>
456&lt;/head>
457&lt;body>
458
459&lt;?php echo validation_errors(); ?>
460
461&lt;?php echo form_open('form'); ?>
462
463&lt;h5>Username&lt;/h5>
464&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?>" size="50" />
465
466&lt;h5>Password&lt;/h5>
467&lt;input type="text" name="password" value="&lt;?php echo set_value('password'); ?>" size="50" />
468
469&lt;h5>Password Confirm&lt;/h5>
470&lt;input type="text" name="passconf" value="&lt;?php echo set_value('passconf'); ?>" size="50" />
471
472&lt;h5>Email Address&lt;/h5>
473&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?>" size="50" />
474
475&lt;div>&lt;input type="submit" value="Submit" />&lt;/div>
476
477&lt;/form>
478
479&lt;/body>
480&lt;/html>
481</textarea>
482
483
Derek Jones37f4b9c2011-07-01 17:56:50 -0500484<p><dfn>Now reload your page and submit the form so that it triggers an error. Your form fields should now be re-populated</dfn></p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000485
486<p class="important"><strong>Note:</strong> The <a href="#functionreference">Function Reference</a> section below contains functions that
487permit you to re-populate &lt;select> menus, radio buttons, and checkboxes.</p>
488
489
Derek Jones37f4b9c2011-07-01 17:56:50 -0500490<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000491
492<code>&lt;input type="text" name="<kbd>colors[]</kbd>" value="&lt;?php echo set_value('<kbd>colors[]</kbd>'); ?>" size="50" /></code>
493
494<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p>
495
496
497
498
499
500<a name="callbacks"></a>
501<h2>Callbacks: Your own Validation Functions</h2>
502
Derek Jones37f4b9c2011-07-01 17:56:50 -0500503<p>The validation system supports callbacks to your own validation functions. This permits you to extend the validation class
504to 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
505create a callback function that does that. Let's create a example of this.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000506
507<p>In your controller, change the "username" rule to this:</p>
508
509<code>$this->form_validation->set_rules('username', 'Username', '<kbd>callback_username_check</kbd>');</code>
510
Derek Jones37f4b9c2011-07-01 17:56:50 -0500511<p>Then add a new function called <dfn>username_check</dfn> to your controller. Here's how your controller should now look:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000512
MarcosCoelho7dafce42011-07-16 02:57:47 -0300513<textarea class="textarea" style="width:100%" cols="50" rows="40">&lt;?php
Derek Allard2067d1a2008-11-13 22:59:24 +0000514
Greg Aker16fcb2e2010-11-09 13:53:07 -0600515class Form extends CI_Controller {
Barry Mienydd671972010-10-04 16:33:58 +0200516
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100517 public function index()
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 {
519 $this->load->helper(array('form', 'url'));
Barry Mienydd671972010-10-04 16:33:58 +0200520
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 $this->load->library('form_validation');
Barry Mienydd671972010-10-04 16:33:58 +0200522
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
524 $this->form_validation->set_rules('password', 'Password', 'required');
525 $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100526 $this->form_validation->set_rules('email', 'Email', 'required|is_unique[users.email]');
Barry Mienydd671972010-10-04 16:33:58 +0200527
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 if ($this->form_validation->run() == FALSE)
529 {
530 $this->load->view('myform');
531 }
532 else
533 {
534 $this->load->view('formsuccess');
535 }
536 }
Barry Mienydd671972010-10-04 16:33:58 +0200537
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100538 public function username_check($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 {
540 if ($str == 'test')
541 {
542 $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
543 return FALSE;
544 }
545 else
546 {
547 return TRUE;
548 }
549 }
Barry Mienydd671972010-10-04 16:33:58 +0200550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551}
552?></textarea>
553
Derek Jones37f4b9c2011-07-01 17:56:50 -0500554<p><dfn>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
Derek Allard2067d1a2008-11-13 22:59:24 +0000555callback function for you to process.</dfn></p>
556
MarcosCoelho7dafce42011-07-16 02:57:47 -0300557<p>To invoke a callback just put the function name in a rule, with "callback_" as the rule <strong>prefix</strong>. If you need
558to receive an extra parameter in your callback function, just add it normally after the function name between square brackets,
559as in: "callback_foo<strong>[bar]</strong>", then it will be passed as the second argument of your callback function.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000560
MarcosCoelho7dafce42011-07-16 02:57:47 -0300561<p><strong>Note:</strong> 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
Derek Allard2067d1a2008-11-13 22:59:24 +0000562it is assumed that the data is your newly processed form data.</p>
563
Derek Allard2067d1a2008-11-13 22:59:24 +0000564<a name="settingerrors"></a>
565<h2>Setting Error Messages</h2>
566
567
Derek Jones37f4b9c2011-07-01 17:56:50 -0500568<p>All of the native error messages are located in the following language file: <dfn>language/english/form_validation_lang.php</dfn></p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000569
570<p>To set your own custom message you can either edit that file, or use the following function:</p>
571
572<code>$this->form_validation->set_message('<var>rule</var>', '<var>Error Message</var>');</code>
573
574<p>Where <var>rule</var> corresponds to the name of a particular rule, and <var>Error Message</var> is the text you would like displayed.</p>
575
576<p>If you include <dfn>%s</dfn> in your error string, it will be replaced with the "human" name you used for your field when you set your rules.</p>
577
578<p>In the "callback" example above, the error message was set by passing the name of the function:</p>
579
580<code>$this->form_validation->set_message('username_check')</code>
581
Derek Jones37f4b9c2011-07-01 17:56:50 -0500582<p>You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000583
584<code>$this->form_validation->set_message('required', 'Your custom message here');</code>
585
586
587
588<a name="translatingfn"></a>
589<h2>Translating Field Names</h2>
590
591<p>If you would like to store the "human" name you passed to the <dfn>set_rules()</dfn> function in a language file, and therefore make the name able to be translated, here's how:</p>
592
593<p>First, prefix your "human" name with <dfn>lang:</dfn>, as in this example:</p>
594
595<code>
596$this->form_validation->set_rules('first_name', '<kbd>lang:</kbd>first_name', 'required');<br />
597</code>
598
599<p>Then, store the name in one of your language file arrays (without the prefix):</p>
600
601<code>$lang['first_name'] = 'First Name';</code>
602
603<p><strong>Note:</strong> 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>
604
605<code>$this->lang->load('file_name');</code>
606
607<p>See the <a href="language.html">Language Class</a> page for more info regarding language files.</p>
608
609
610<a name="errordelimiters"></a>
611<h2>Changing the Error Delimiters</h2>
612
Barry Mienydd671972010-10-04 16:33:58 +0200613<p>By default, the Form Validation class adds a paragraph tag (&lt;p&gt;) around each error message shown. You can either change these delimiters globally or
Derek Allard2067d1a2008-11-13 22:59:24 +0000614individually.</p>
615
616<ol>
617
618<li><strong>Changing delimiters Globally</strong>
619
620<p>To globally change the error delimiters, in your controller function, just after loading the Form Validation class, add this:</p>
621
622<code>$this->form_validation->set_error_delimiters('<kbd>&lt;div class="error"></kbd>', '<kbd>&lt;/div></kbd>');</code>
623
624<p>In this example, we've switched to using div tags.</p>
625
626</li>
627
628<li><strong>Changing delimiters Individually</strong>
629
630<p>Each of the two error generating functions shown in this tutorial can be supplied their own delimiters as follows:</p>
631
632<code>&lt;?php echo form_error('field name', '<kbd>&lt;div class="error"></kbd>', '<kbd>&lt;/div></kbd>'); ?></code>
633
634<p>Or:</p>
635
636<code>&lt;?php echo validation_errors('<kbd>&lt;div class="error"></kbd>', '<kbd>&lt;/div></kbd>'); ?></code>
637
638</li>
639</ol>
640
641
642
643
644<a name="individualerrors"></a>
645<h2>Showing Errors Individually</h2>
646
647<p>If you prefer to show an error message next to each form field, rather than as a list, you can use the <dfn>form_error()</dfn> function.</p>
648
649<p>Try it! Change your form so that it looks like this:</p>
650
651<textarea class="textarea" style="width:100%" cols="50" rows="18">
652&lt;h5>Username&lt;/h5>
653&lt;?php echo form_error('username'); ?>
654&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?>" size="50" />
655
656&lt;h5>Password&lt;/h5>
657&lt;?php echo form_error('password'); ?>
658&lt;input type="text" name="password" value="&lt;?php echo set_value('password'); ?>" size="50" />
659
660&lt;h5>Password Confirm&lt;/h5>
661&lt;?php echo form_error('passconf'); ?>
662&lt;input type="text" name="passconf" value="&lt;?php echo set_value('passconf'); ?>" size="50" />
663
664&lt;h5>Email Address&lt;/h5>
665&lt;?php echo form_error('email'); ?>
666&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?>" size="50" />
667</textarea>
668
Derek Jones37f4b9c2011-07-01 17:56:50 -0500669<p>If there are no errors, nothing will be shown. If there is an error, the message will appear.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000670
Derek Jones37f4b9c2011-07-01 17:56:50 -0500671<p><strong>Important Note:</strong> If you use an array as the name of a form field, you must supply it as an array to the function. Example:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000672
673<code>&lt;?php echo form_error('<kbd>options[size]</kbd>'); ?><br />
674&lt;input type="text" name="<kbd>options[size]</kbd>" value="&lt;?php echo set_value("<kbd>options[size]</kbd>"); ?>" size="50" />
675</code>
676
677<p>For more info please see the <a href="#arraysasfields">Using Arrays as Field Names</a> section below.</p>
678
679
680
681
682<p>&nbsp;</p>
683
684
685<a name="savingtoconfig"></a>
686<h1>Saving Sets of Validation Rules to a Config File</h1>
687
Derek Jones37f4b9c2011-07-01 17:56:50 -0500688<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
689can organize these rules into "groups". These groups can either be loaded automatically when a matching controller/function is called, or
Derek Allard2067d1a2008-11-13 22:59:24 +0000690you can manually call each set as needed.</p>
691
692<h3>How to save your rules</h3>
693
694<p>To store your validation rules, simply create a file named <kbd>form_validation.php</kbd> in your <dfn>application/config/</dfn> folder.
695In that file you will place an array named <kbd>$config</kbd> with your rules. As shown earlier, the validation array will have this prototype:</p>
696
697<code>
698$config = array(<br />
699&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
700&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field'&nbsp;&nbsp;&nbsp;=> 'username', <br />
701&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label'&nbsp;&nbsp;&nbsp;=> 'Username', <br />
702&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rules'&nbsp;&nbsp;&nbsp;=> 'required'<br />
703&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />
704&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
705&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field'&nbsp;&nbsp;&nbsp;=> 'password', <br />
706&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label'&nbsp;&nbsp;&nbsp;=> 'Password', <br />
707&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rules'&nbsp;&nbsp;&nbsp;=> 'required'<br />
708&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />
709&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
710&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field'&nbsp;&nbsp;&nbsp;=> 'passconf', <br />
711&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label'&nbsp;&nbsp;&nbsp;=> 'Password Confirmation', <br />
712&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rules'&nbsp;&nbsp;&nbsp;=> 'required'<br />
713&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),&nbsp;&nbsp;&nbsp;<br />
714&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
715&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field'&nbsp;&nbsp;&nbsp;=> 'email', <br />
716&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label'&nbsp;&nbsp;&nbsp;=> 'Email', <br />
717&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rules'&nbsp;&nbsp;&nbsp;=> 'required'<br />
718&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br />
719&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
720</code>
721
722<p><dfn>Your validation rule file will be loaded automatically and used when you call the run() function.</dfn></p>
723
724<p class="important">Please note that you MUST name your array $config.</p>
725
726<h3>Creating Sets of Rules</h3>
727
Derek Jones37f4b9c2011-07-01 17:56:50 -0500728<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.
729We've arbitrarily called these two rules "signup" and "email". You can name your rules anything you want:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000730
731
732<code>$config = array(<br />
733&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<kbd>signup</kbd>' => array(<br />
734&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
735&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'field' => 'username',<br />
736&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'label' => 'Username',<br />
737&nb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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
777&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
778</code>
779
780
781<h3>Calling a Specific Rule Group</h3>
782
Derek Jones37f4b9c2011-07-01 17:56:50 -0500783<p>In order to call a specific group you will pass its name to the <kbd>run()</kbd> function. For example, to call the <kbd>signup</kbd> rule you will do this:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000784
785<code>
786if ($this->form_validation->run('<kbd>signup</kbd>') == FALSE)<br />
787{<br />
788&nbsp;&nbsp;&nbsp;$this->load->view('myform');<br />
789}<br />
790else<br />
791{<br />
792&nbsp;&nbsp;&nbsp;$this->load->view('formsuccess');<br />
793}<br />
794</code>
795
796
797
798<h3>Associating a Controller Function with a Rule Group</h3>
799
Derek Jones37f4b9c2011-07-01 17:56:50 -0500800<p>An alternate (and more automatic) method of calling a rule group is to name it according to the controller class/function you intend to use it with. For example, let's say you
801have a controller named <kbd>Member</kbd> and a function named <kbd>signup</kbd>. Here's what your class might look like:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000802
803<code>
804&lt;?php<br /><br />
Greg Aker16fcb2e2010-11-09 13:53:07 -0600805class <kbd>Member</kbd> extends CI_Controller {<br />
Derek Allard2067d1a2008-11-13 22:59:24 +0000806<br />
807&nbsp;&nbsp;&nbsp;function <kbd>signup</kbd>()<br />
808&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
809&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->load->library('form_validation');<br />
810&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
811&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($this->form_validation->run() == FALSE)<br />
812&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
813&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->load->view('myform');<br />
814&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
815&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
816&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
817&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->load->view('formsuccess');<br />
818&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
819&nbsp;&nbsp;&nbsp;}<br />
820}<br />
821?></code>
822
823<p>In your validation config file, you will name your rule group <kbd>member/signup</kbd>:</p>
824
825
826<code>$config = array(<br />
Derek Allard03d783b2009-05-03 19:45:45 +0000827&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'<kbd>member/signup</kbd>' => array(<br />
Derek Allard2067d1a2008-11-13 22:59:24 +0000828&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array(<br />
829&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br />
849&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
850</code>
851
852<p><dfn>When a rule group is named identically to a controller class/function it will be used automatically when the run() function is invoked from that class/function.</dfn></p>
853
854<p>&nbsp;</p>
855
856
857<a name="arraysasfields"></a>
858<h1>Using Arrays as Field Names</h1>
859
Derek Jones37f4b9c2011-07-01 17:56:50 -0500860<p>The Form Validation class supports the use of arrays as field names. Consider this example:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000861
862<code>&lt;input type="text" name="<kbd>options[]</kbd>" value="" size="50" /></code>
863
864<p>If you do use an array as a field name, you must use the EXACT array name in the <a href="#helperreference">Helper Functions</a> that require the field name,
865and as your Validation Rule field name.</p>
866
867<p>For example, to set a rule for the above field you would use:</p>
868
869<code>$this->form_validation->set_rules('<kbd>options[]</kbd>', 'Options', 'required');</code>
870
871<p>Or, to show an error for the above field you would use:</p>
872
873<code>&lt;?php echo form_error('<kbd>options[]</kbd>'); ?></code>
874
875<p>Or to re-populate the field you would use:</p>
876
877<code>&lt;input type="text" name="<kbd>options[]</kbd>" value="<kbd>&lt;?php echo set_value('<kbd>options[]</kbd>'); ?></kbd>" size="50" /></code>
878
879<p>You can use multidimensional arrays as field names as well. For example:</p>
880
881<code>&lt;input type="text" name="<kbd>options[size]</kbd>" value="" size="50" /></code>
882
883<p>Or even:</p>
884
885<code>&lt;input type="text" name="<kbd>sports[nba][basketball]</kbd>" value="" size="50" /></code>
886
887<p>As with our first example, you must use the exact array name in the helper functions:</p>
888
889<code>&lt;?php echo form_error('<kbd>sports[nba][basketball]</kbd>'); ?></code>
890
891<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
892POST array:</p>
893
894<code>
895&lt;input type="checkbox" name="<kbd>options[]</kbd>" value="red" /><br />
896&lt;input type="checkbox" name="<kbd>options[]</kbd>" value="blue" /><br />
897&lt;input type="checkbox" name="<kbd>options[]</kbd>" value="green" />
898</code>
899
900<p>Or if you use a multidimensional array:</p>
901
902<code>
903&lt;input type="checkbox" name="<kbd>options[color][]</kbd>" value="red" /><br />
904&lt;input type="checkbox" name="<kbd>options[color][]</kbd>" value="blue" /><br />
905&lt;input type="checkbox" name="<kbd>options[color][]</kbd>" value="green" />
906</code>
907
908<p>When you use a helper function you'll include the bracket as well:</p>
909
910<code>&lt;?php echo form_error('<kbd>options[color][]</kbd>'); ?></code>
911
912
913
914
915<p>&nbsp;</p>
916
917
918<a name="rulereference"></a>
919<h1>Rule Reference</h1>
920
921<p>The following is a list of all the native rules that are available to use:</p>
922
923
Derek Allard2067d1a2008-11-13 22:59:24 +0000924<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
Phil Sturgeonef112c02011-02-07 13:01:47 +0000925 <tr>
926 <th>Rule</th>
927 <th>Parameter</th>
928 <th>Description</th>
929 <th>Example</th>
930 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000931
Phil Sturgeonef112c02011-02-07 13:01:47 +0000932 <tr>
933 <td class="td"><strong>required</strong></td>
934 <td class="td">No</td>
935 <td class="td">Returns FALSE if the form element is empty.</td>
936 <td class="td">&nbsp;</td>
937 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000938
Phil Sturgeonef112c02011-02-07 13:01:47 +0000939 <tr>
940 <td class="td"><strong>matches</strong></td>
941 <td class="td">Yes</td>
942 <td class="td">Returns FALSE if the form element does not match the one in the parameter.</td>
943 <td class="td">matches[form_item]</td>
944 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000945
Phil Sturgeonef112c02011-02-07 13:01:47 +0000946 <tr>
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100947 <td class="td"><strong>is_unique</strong></td>
948 <td class="td">Yes</td>
949 <td class="td">Returns FALSE if the form element is not unique to the table and field name in the parameter.</td>
950 <td class="td">is_unique[table.field]</td>
951 </tr>
952
953 <tr>
Phil Sturgeonef112c02011-02-07 13:01:47 +0000954 <td class="td"><strong>min_length</strong></td>
955 <td class="td">Yes</td>
956 <td class="td">Returns FALSE if the form element is shorter then the parameter value.</td>
957 <td class="td">min_length[6]</td>
958 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000959
Phil Sturgeonef112c02011-02-07 13:01:47 +0000960 <tr>
961 <td class="td"><strong>max_length</strong></td>
962 <td class="td">Yes</td>
963 <td class="td">Returns FALSE if the form element is longer then the parameter value.</td>
964 <td class="td">max_length[12]</td>
965 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000966
Phil Sturgeonef112c02011-02-07 13:01:47 +0000967 <tr>
968 <td class="td"><strong>exact_length</strong></td>
969 <td class="td">Yes</td>
970 <td class="td">Returns FALSE if the form element is not exactly the parameter value.</td>
971 <td class="td">exact_length[8]</td>
972 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000973
Phil Sturgeonef112c02011-02-07 13:01:47 +0000974 <tr>
975 <td class="td"><strong>greater_than</strong></td>
976 <td class="td">Yes</td>
977 <td class="td">Returns FALSE if the form element is less than the parameter value or not numeric.</td>
978 <td class="td">greater_than[8]</td>
979 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000980
Phil Sturgeonef112c02011-02-07 13:01:47 +0000981 <tr>
982 <td class="td"><strong>less_than</strong></td>
983 <td class="td">Yes</td>
984 <td class="td">Returns FALSE if the form element is greater than the parameter value or not numeric.</td>
985 <td class="td">less_than[8]</td>
986 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000987
Phil Sturgeonef112c02011-02-07 13:01:47 +0000988 <tr>
989 <td class="td"><strong>alpha</strong></td>
990 <td class="td">No</td>
991 <td class="td">Returns FALSE if the form element contains anything other than alphabetical characters.</td>
992 <td class="td">&nbsp;</td>
993 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +0000994
Phil Sturgeonef112c02011-02-07 13:01:47 +0000995 <tr>
996 <td class="td"><strong>alpha_numeric</strong></td>
997 <td class="td">No</td>
998 <td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters.</td>
999 <td class="td">&nbsp;</td>
1000 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001001
Phil Sturgeonef112c02011-02-07 13:01:47 +00001002 <tr>
1003 <td class="td"><strong>alpha_dash</strong></td>
1004 <td class="td">No</td>
1005 <td class="td">Returns FALSE if the form element contains anything other than alpha-numeric characters, underscores or dashes.</td>
1006 <td class="td">&nbsp;</td>
1007 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001008
Phil Sturgeonef112c02011-02-07 13:01:47 +00001009 <tr>
1010 <td class="td"><strong>numeric</strong></td>
1011 <td class="td">No</td>
1012 <td class="td">Returns FALSE if the form element contains anything other than numeric characters.</td>
1013 <td class="td">&nbsp;</td>
1014 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001015
Phil Sturgeonef112c02011-02-07 13:01:47 +00001016 <tr>
1017 <td class="td"><strong>integer</strong></td>
1018 <td class="td">No</td>
1019 <td class="td">Returns FALSE if the form element contains anything other than an integer.</td>
1020 <td class="td">&nbsp;</td>
1021 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001022
Phil Sturgeonef112c02011-02-07 13:01:47 +00001023 <tr>
1024 <td class="td"><strong>decimal</strong></td>
1025 <td class="td">Yes</td>
1026 <td class="td">Returns FALSE if the form element is not exactly the parameter value.</td>
1027 <td class="td">&nbsp;</td>
1028 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001029
Phil Sturgeonef112c02011-02-07 13:01:47 +00001030 <tr>
1031 <td class="td"><strong>is_natural</strong></td>
1032 <td class="td">No</td>
1033 <td class="td">Returns FALSE if the form element contains anything other than a natural number: 0, 1, 2, 3, etc.</td>
1034 <td class="td">&nbsp;</td>
1035 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001036
Phil Sturgeonef112c02011-02-07 13:01:47 +00001037 <tr>
1038 <td class="td"><strong>is_natural_no_zero</strong></td>
1039 <td class="td">No</td>
1040 <td class="td">Returns FALSE if the form element contains anything other than a natural number, but not zero: 1, 2, 3, etc.</td>
1041 <td class="td">&nbsp;</td>
1042 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001043
Phil Sturgeonef112c02011-02-07 13:01:47 +00001044 <tr>
Kyle Farrisd9c3a6f2011-08-21 23:08:17 -03001045 <td class="td"><strong>is_unique</strong></td>
1046 <td class="td">Yes</td>
1047 <td class="td">Returns FALSE if the form element is not unique in a database table.</td>
1048 <td class="td">is_unique[table.field]</td>
1049 </tr>
1050
1051 <tr>
Phil Sturgeonef112c02011-02-07 13:01:47 +00001052 <td class="td"><strong>valid_email</strong></td>
1053 <td class="td">No</td>
1054 <td class="td">Returns FALSE if the form element does not contain a valid email address.</td>
1055 <td class="td">&nbsp;</td>
1056 </tr>
1057
1058 <tr>
1059 <td class="td"><strong>valid_emails</strong></td>
1060 <td class="td">No</td>
1061 <td class="td">Returns FALSE if any value provided in a comma separated list is not a valid email.</td>
1062 <td class="td">&nbsp;</td>
1063 </tr>
1064
1065 <tr>
1066 <td class="td"><strong>valid_ip</strong></td>
1067 <td class="td">No</td>
1068 <td class="td">Returns FALSE if the supplied IP is not valid.</td>
1069 <td class="td">&nbsp;</td>
1070 </tr>
1071
1072 <tr>
1073 <td class="td"><strong>valid_base64</strong></td>
1074 <td class="td">No</td>
1075 <td class="td">Returns FALSE if the supplied string contains anything other than valid Base64 characters.</td>
1076 <td class="td">&nbsp;</td>
1077 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001078
1079
1080</table>
1081
1082<p><strong>Note:</strong> These rules can also be called as discrete functions. For example:</p>
1083
1084<code>$this->form_validation->required($string);</code>
1085
1086<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter.</p>
1087
1088
1089
1090<p>&nbsp;</p>
1091
1092<a name="preppingreference"></a>
1093<h1>Prepping Reference</h1>
1094
1095<p>The following is a list of all the prepping functions that are available to use:</p>
1096
1097
1098
1099<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
Phil Sturgeonef112c02011-02-07 13:01:47 +00001100 <tr>
1101 <th>Name</th>
1102 <th>Parameter</th>
1103 <th>Description</th>
1104 </tr><tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001105
Phil Sturgeonef112c02011-02-07 13:01:47 +00001106 <td class="td"><strong>xss_clean</strong></td>
1107 <td class="td">No</td>
1108 <td class="td">Runs the data through the XSS filtering function, described in the <a href="input.html">Input Class</a> page.</td>
1109 </tr><tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001110
Phil Sturgeonef112c02011-02-07 13:01:47 +00001111 <td class="td"><strong>prep_for_form</strong></td>
1112 <td class="td">No</td>
1113 <td class="td">Converts special characters so that HTML data can be shown in a form field without breaking it.</td>
1114 </tr><tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001115
Phil Sturgeonef112c02011-02-07 13:01:47 +00001116 <td class="td"><strong>prep_url</strong></td>
1117 <td class="td">No</td>
1118 <td class="td">Adds "http://" to URLs if missing.</td>
1119 </tr><tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001120
Phil Sturgeonef112c02011-02-07 13:01:47 +00001121 <td class="td"><strong>strip_image_tags</strong></td>
1122 <td class="td">No</td>
1123 <td class="td">Strips the HTML from image tags leaving the raw URL.</td>
1124 </tr><tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001125
Phil Sturgeonef112c02011-02-07 13:01:47 +00001126 <td class="td"><strong>encode_php_tags</strong></td>
1127 <td class="td">No</td>
1128 <td class="td">Converts PHP tags to entities.</td>
1129 </tr>
Derek Allard2067d1a2008-11-13 22:59:24 +00001130
1131</table>
1132
1133<p class="important"><strong>Note:</strong> You can also use any native PHP functions that permit one parameter,
1134like <kbd>trim</kbd>, <kbd>htmlspecialchars</kbd>, <kbd>urldecode</kbd>, etc.</p>
1135
1136
1137
1138
1139
1140
1141
1142<p>&nbsp;</p>
1143
1144<a name="functionreference"></a>
1145<h1>Function Reference</h1>
1146
1147<p>The following functions are intended for use in your controller functions.</p>
1148
Derek Allard51157252009-02-04 12:34:07 +00001149<h2>$this->form_validation->set_rules();</h2>
Derek Allard2067d1a2008-11-13 22:59:24 +00001150
1151<p>Permits you to set validation rules, as described in the tutorial sections above:</p>
1152
1153<ul>
1154<li><a href="#validationrules">Setting Validation Rules</a></li>
1155<li><a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a></li>
1156</ul>
1157
1158
1159<h2>$this->form_validation->run();</h2>
1160
Derek Jones37f4b9c2011-07-01 17:56:50 -05001161<p>Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation
Derek Allard2067d1a2008-11-13 22:59:24 +00001162group via the function, as described in: <a href="#savingtoconfig">Saving Groups of Validation Rules to a Config File</a>.</p>
1163
1164
1165<h2>$this->form_validation->set_message();</h2>
1166
Derek Jones37f4b9c2011-07-01 17:56:50 -05001167<p>Permits you to set custom error messages. See <a href="#settingerrors">Setting Error Messages</a> above.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001168
1169
1170<p>&nbsp;</p>
1171
1172<a name="helperreference"></a>
1173<h1>Helper Reference</h1>
1174
Derek Jones37f4b9c2011-07-01 17:56:50 -05001175<p>The following helper functions are available for use in the view files containing your forms. Note that these are procedural functions, so they
Derek Allard2067d1a2008-11-13 22:59:24 +00001176<strong>do not</strong> require you to prepend them with $this->form_validation.</p>
1177
1178<h2>form_error()</h2>
1179
Derek Jones37f4b9c2011-07-01 17:56:50 -05001180<p>Shows an individual error message associated with the field name supplied to the function. Example:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001181
1182<code>&lt;?php echo form_error('username'); ?></code>
1183
Derek Jones37f4b9c2011-07-01 17:56:50 -05001184<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001185
1186
1187
1188<h2>validation_errors()</h2>
Derek Jones37f4b9c2011-07-01 17:56:50 -05001189<p>Shows all error messages as a string: Example:</p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001190
1191<code>&lt;?php echo validation_errors(); ?></code>
1192
Derek Jones37f4b9c2011-07-01 17:56:50 -05001193<p>The error delimiters can be optionally specified. See the <a href="#errordelimiters">Changing the Error Delimiters</a> section above.</p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001194
1195
1196
1197<h2>set_value()</h2>
1198
1199<p>Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function.
1200The second (optional) parameter allows you to set a default value for the form. Example:</p>
1201
1202<code>&lt;input type="text" name="quantity" value="<dfn>&lt;?php echo set_value('quantity', '0'); ?></dfn>" size="50" /></code>
1203
1204<p>The above form will show "0" when loaded for the first time.</p>
1205
1206<h2>set_select()</h2>
1207
Derek Jones37f4b9c2011-07-01 17:56:50 -05001208<p>If you use a <dfn>&lt;select></dfn> menu, this function permits you to display the menu item that was selected. The first parameter
Derek Allard2067d1a2008-11-13 22:59:24 +00001209must contain the name of the select menu, the second parameter must contain the value of
1210each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p>
1211
1212<p>Example:</p>
1213
1214<code>
1215&lt;select name="myselect"><br />
Derek Jones37f4b9c2011-07-01 17:56:50 -05001216&lt;option value="one" <dfn>&lt;?php echo set_select('myselect', 'one', TRUE); ?></dfn> >One&lt;/option><br />
1217&lt;option value="two" <dfn>&lt;?php echo set_select('myselect', 'two'); ?></dfn> >Two&lt;/option><br />
1218&lt;option value="three" <dfn>&lt;?php echo set_select('myselect', 'three'); ?></dfn> >Three&lt;/option><br />
Derek Allard2067d1a2008-11-13 22:59:24 +00001219&lt;/select>
1220</code>
1221
1222
1223<h2>set_checkbox()</h2>
1224
Derek Jones37f4b9c2011-07-01 17:56:50 -05001225<p>Permits you to display a checkbox in the state it was submitted. The first parameter
Derek Allard2067d1a2008-11-13 22:59:24 +00001226must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:</p>
1227
1228<code>&lt;input type="checkbox" name="mycheck[]" value="1" <dfn>&lt;?php echo set_checkbox('mycheck[]', '1'); ?></dfn> /><br />
1229&lt;input type="checkbox" name="mycheck[]" value="2" <dfn>&lt;?php echo set_checkbox('mycheck[]', '2'); ?></dfn> /></code>
1230
1231
1232<h2>set_radio()</h2>
1233
1234<p>Permits you to display radio buttons in the state they were submitted. This function is identical to the <strong>set_checkbox()</strong> function above.</p>
1235
Derek Jones37f4b9c2011-07-01 17:56:50 -05001236<code>&lt;input type="radio" name="myradio" value="1" <dfn>&lt;?php echo set_radio('myradio', '1', TRUE); ?></dfn> /><br />
1237&lt;input type="radio" name="myradio" value="2" <dfn>&lt;?php echo set_radio('myradio', '2'); ?></dfn> /></code>
Derek Allard2067d1a2008-11-13 22:59:24 +00001238
1239
1240
1241</div>
1242<!-- END CONTENT -->
1243
1244
1245<div id="footer">
1246<p>
1247Previous Topic:&nbsp;&nbsp;<a href="file_uploading.html">File Uploading Class</a>
1248&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
1249<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
1250<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
1251Next Topic:&nbsp;&nbsp;<a href="ftp.html">FTP Class</a>
1252</p>
Derek Jones700205a2011-01-28 07:44:28 -06001253<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 - 2011 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">EllisLab, Inc.</a></p>
Derek Allard2067d1a2008-11-13 22:59:24 +00001254</div>
1255
1256</body>
Rick Ellis25949532008-08-26 19:48:08 +00001257</html>