blob: cdb3d3d627a31bdae8e4d8101882be47c13abc15 [file] [log] [blame]
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Eric Barnescccde962011-12-04 00:01:17 -05008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Eric Barnescccde962011-12-04 00:01:17 -050010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Form Validation Class
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Validation
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/form_validation.html
38 */
39class CI_Form_validation {
Barry Mienydd671972010-10-04 16:33:58 +020040
Phil Sturgeon3837ae72011-05-09 21:12:26 +010041 protected $CI;
42 protected $_field_data = array();
43 protected $_config_rules = array();
44 protected $_error_array = array();
45 protected $_error_messages = array();
46 protected $_error_prefix = '<p>';
47 protected $_error_suffix = '</p>';
48 protected $error_string = '';
49 protected $_safe_form_data = FALSE;
JonoB099c4782012-03-04 14:37:30 +000050 protected $validation_data = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000051
Greg Akera9263282010-11-10 15:26:43 -060052 public function __construct($rules = array())
Barry Mienydd671972010-10-04 16:33:58 +020053 {
Derek Allard2067d1a2008-11-13 22:59:24 +000054 $this->CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +020055
Derek Allard2067d1a2008-11-13 22:59:24 +000056 // Validation rules can be stored in a config file.
57 $this->_config_rules = $rules;
Barry Mienydd671972010-10-04 16:33:58 +020058
Derek Allard2067d1a2008-11-13 22:59:24 +000059 // Automatically load the form helper
60 $this->CI->load->helper('form');
61
62 // Set the character encoding in MB.
63 if (function_exists('mb_internal_encoding'))
64 {
65 mb_internal_encoding($this->CI->config->item('charset'));
66 }
Barry Mienydd671972010-10-04 16:33:58 +020067
Derek Allard2067d1a2008-11-13 22:59:24 +000068 log_message('debug', "Form Validation Class Initialized");
69 }
Barry Mienydd671972010-10-04 16:33:58 +020070
Derek Allard2067d1a2008-11-13 22:59:24 +000071 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020072
Derek Allard2067d1a2008-11-13 22:59:24 +000073 /**
74 * Set Rules
75 *
76 * This function takes an array of field names and validation
77 * rules as input, validates the info, and stores it
78 *
Derek Allard2067d1a2008-11-13 22:59:24 +000079 * @param mixed
80 * @param string
81 * @return void
82 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +010083 public function set_rules($field, $label = '', $rules = '')
Derek Allard2067d1a2008-11-13 22:59:24 +000084 {
85 // No reason to set rules if we have no POST data
JonoB099c4782012-03-04 14:37:30 +000086 // or a validation array has not been specified
87 if (count($_POST) === 0 && count($this->validation_data) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +000088 {
Greg Aker9f9af602010-11-10 15:41:51 -060089 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +000090 }
Barry Mienydd671972010-10-04 16:33:58 +020091
Derek Allard2067d1a2008-11-13 22:59:24 +000092 // If an array was passed via the first parameter instead of indidual string
93 // values we cycle through it and recursively call this function.
94 if (is_array($field))
95 {
96 foreach ($field as $row)
97 {
98 // Houston, we have a problem...
99 if ( ! isset($row['field']) OR ! isset($row['rules']))
100 {
101 continue;
102 }
103
104 // If the field label wasn't passed we use the field name
105 $label = ( ! isset($row['label'])) ? $row['field'] : $row['label'];
106
107 // Here we go!
108 $this->set_rules($row['field'], $label, $row['rules']);
109 }
Greg Aker9f9af602010-11-10 15:41:51 -0600110 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 }
Barry Mienydd671972010-10-04 16:33:58 +0200112
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 // No fields? Nothing to do...
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200114 if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 {
Greg Aker9f9af602010-11-10 15:41:51 -0600116 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000117 }
118
119 // If the field label wasn't passed we use the field name
120 $label = ($label == '') ? $field : $label;
121
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200122 // Is the field name an array? If it is an array, we break it apart
Barry Mienydd671972010-10-04 16:33:58 +0200123 // into its components so that we can fetch the corresponding POST data later
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200124 if (preg_match_all('/\[(.*?)\]/', $field, $matches))
Barry Mienydd671972010-10-04 16:33:58 +0200125 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 // Note: Due to a bug in current() that affects some versions
127 // of PHP we can not pass function call directly into it
128 $x = explode('[', $field);
129 $indexes[] = current($x);
130
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200131 for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200133 if ($matches[1][$i] != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200135 $indexes[] = $matches[1][$i];
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 }
137 }
Barry Mienydd671972010-10-04 16:33:58 +0200138
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 $is_array = TRUE;
140 }
141 else
142 {
Barry Mienydd671972010-10-04 16:33:58 +0200143 $indexes = array();
144 $is_array = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 }
Barry Mienydd671972010-10-04 16:33:58 +0200146
147 // Build our master array
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 $this->_field_data[$field] = array(
Phil Sturgeonef112c02011-02-07 13:01:47 +0000149 'field' => $field,
150 'label' => $label,
151 'rules' => $rules,
152 'is_array' => $is_array,
153 'keys' => $indexes,
154 'postdata' => NULL,
155 'error' => ''
156 );
Greg Aker9f9af602010-11-10 15:41:51 -0600157
158 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 }
160
161 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200162
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 /**
JonoB099c4782012-03-04 14:37:30 +0000164 * By default, form validation uses the $_POST array to validate
Andrey Andreevc8da4fe2012-03-04 19:20:33 +0200165 *
JonoB099c4782012-03-04 14:37:30 +0000166 * If an array is set through this method, then this array will
167 * be used instead of the $_POST array
JonoB883f80f2012-03-05 09:51:27 +0000168 *
169 * Note that if you are validating multiple arrays, then the
170 * reset_validation() function should be called after validating
171 * each array due to the limitations of CI's singleton
Andrey Andreevc8da4fe2012-03-04 19:20:33 +0200172 *
173 * @param array $data
174 * @return void
JonoB099c4782012-03-04 14:37:30 +0000175 */
176 public function set_data($data = '')
177 {
178 if ( ! empty($data) && is_array($data))
179 {
Andrey Andreevc8da4fe2012-03-04 19:20:33 +0200180 $this->validation_data = $data;
JonoB099c4782012-03-04 14:37:30 +0000181 }
182 }
Andrey Andreevc8da4fe2012-03-04 19:20:33 +0200183
JonoB099c4782012-03-04 14:37:30 +0000184 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000185
186 /**
187 * Set Error Message
188 *
Derek Jones37f4b9c2011-07-01 17:56:50 -0500189 * Lets users set their own error messages on the fly. Note: The key
JonoB099c4782012-03-04 14:37:30 +0000190 * name has to match the function name that it corresponds to.
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 * @param string
193 * @param string
194 * @return string
195 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100196 public function set_message($lang, $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 {
198 if ( ! is_array($lang))
199 {
200 $lang = array($lang => $val);
201 }
Barry Mienydd671972010-10-04 16:33:58 +0200202
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 $this->_error_messages = array_merge($this->_error_messages, $lang);
Phil Sturgeonc3828712011-01-19 12:31:47 +0000204
Greg Aker9f9af602010-11-10 15:41:51 -0600205 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 }
Barry Mienydd671972010-10-04 16:33:58 +0200207
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 /**
211 * Set The Error Delimiter
212 *
213 * Permits a prefix/suffix to be added to each error message
214 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 * @param string
216 * @param string
217 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200218 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100219 public function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 {
221 $this->_error_prefix = $prefix;
222 $this->_error_suffix = $suffix;
Phil Sturgeonc3828712011-01-19 12:31:47 +0000223
Greg Aker9f9af602010-11-10 15:41:51 -0600224 return $this;
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 }
226
227 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 /**
230 * Get Error Message
231 *
232 * Gets the error message associated with a particular field
233 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 * @param string the field name
235 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200236 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100237 public function error($field = '', $prefix = '', $suffix = '')
Barry Mienydd671972010-10-04 16:33:58 +0200238 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '')
240 {
241 return '';
242 }
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 if ($prefix == '')
245 {
246 $prefix = $this->_error_prefix;
247 }
248
249 if ($suffix == '')
250 {
251 $suffix = $this->_error_suffix;
252 }
253
254 return $prefix.$this->_field_data[$field]['error'].$suffix;
255 }
256
257 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200258
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 /**
Michiel Vugteveen676a0dd2012-03-02 10:10:34 +0100260 * Get Array of Error Messages
261 *
262 * Returns the error messages as an array
263 *
264 * @return array
265 */
266 public function error_array()
267 {
268 return $this->_error_array;
269 }
270
271 // --------------------------------------------------------------------
272
273 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 * Error String
275 *
276 * Returns the error messages as a string, wrapped in the error delimiters
277 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 * @param string
279 * @param string
280 * @return str
Barry Mienydd671972010-10-04 16:33:58 +0200281 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100282 public function error_string($prefix = '', $suffix = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 {
284 // No errrors, validation passes!
285 if (count($this->_error_array) === 0)
286 {
287 return '';
288 }
Barry Mienydd671972010-10-04 16:33:58 +0200289
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 if ($prefix == '')
291 {
292 $prefix = $this->_error_prefix;
293 }
294
295 if ($suffix == '')
296 {
297 $suffix = $this->_error_suffix;
298 }
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 // Generate the error string
301 $str = '';
302 foreach ($this->_error_array as $val)
303 {
304 if ($val != '')
305 {
306 $str .= $prefix.$val.$suffix."\n";
307 }
308 }
Barry Mienydd671972010-10-04 16:33:58 +0200309
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 return $str;
311 }
312
313 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 /**
316 * Run the Validator
317 *
318 * This function does all the work.
319 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200321 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100322 public function run($group = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500324 // Do we even have any data to process? Mm?
JonoB099c4782012-03-04 14:37:30 +0000325 $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
326 if (count($validation_array) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 {
328 return FALSE;
329 }
Barry Mienydd671972010-10-04 16:33:58 +0200330
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 // Does the _field_data array containing the validation rules exist?
332 // If not, we look to see if they were assigned via a config file
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200333 if (count($this->_field_data) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500335 // No validation rules? We're done...
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200336 if (count($this->_config_rules) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 {
338 return FALSE;
339 }
Barry Mienydd671972010-10-04 16:33:58 +0200340
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 // Is there a validation rule for the particular URI being accessed?
342 $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
Barry Mienydd671972010-10-04 16:33:58 +0200343
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 if ($uri != '' AND isset($this->_config_rules[$uri]))
345 {
346 $this->set_rules($this->_config_rules[$uri]);
347 }
348 else
349 {
350 $this->set_rules($this->_config_rules);
351 }
Barry Mienydd671972010-10-04 16:33:58 +0200352
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 // We're we able to set the rules correctly?
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200354 if (count($this->_field_data) === 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 {
356 log_message('debug', "Unable to find validation rules");
357 return FALSE;
358 }
359 }
Barry Mienydd671972010-10-04 16:33:58 +0200360
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 // Load the language file containing error messages
362 $this->CI->lang->load('form_validation');
Barry Mienydd671972010-10-04 16:33:58 +0200363
364 // Cycle through the rules for each field, match the
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 // corresponding $_POST item and test for errors
366 foreach ($this->_field_data as $field => $row)
Barry Mienydd671972010-10-04 16:33:58 +0200367 {
JonoB099c4782012-03-04 14:37:30 +0000368 // Fetch the data from the corresponding $_POST or validation array and cache it in the _field_data array.
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 // Depending on whether the field name is an array or a string will determine where we get it from.
Barry Mienydd671972010-10-04 16:33:58 +0200370
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200371 if ($row['is_array'] === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 {
JonoB099c4782012-03-04 14:37:30 +0000373 $this->_field_data[$field]['postdata'] = $this->_reduce_array($validation_array, $row['keys']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 }
375 else
376 {
JonoB099c4782012-03-04 14:37:30 +0000377 if (isset($validation_array[$field]) AND $validation_array[$field] != "")
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 {
JonoB099c4782012-03-04 14:37:30 +0000379 $this->_field_data[$field]['postdata'] = $validation_array[$field];
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 }
381 }
Barry Mienydd671972010-10-04 16:33:58 +0200382
383 $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 }
385
386 // Did we end up with any errors?
387 $total_errors = count($this->_error_array);
388
389 if ($total_errors > 0)
390 {
391 $this->_safe_form_data = TRUE;
392 }
393
394 // Now we need to re-set the POST data with the new, processed data
395 $this->_reset_post_array();
Barry Mienydd671972010-10-04 16:33:58 +0200396
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200397 return ($total_errors === 0);
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 }
399
400 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200401
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 /**
403 * Traverse a multidimensional $_POST array index until the data is found
404 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 * @param array
406 * @param array
407 * @param integer
408 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200409 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100410 protected function _reduce_array($array, $keys, $i = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200412 if (is_array($array) && isset($keys[$i]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200414 return isset($array[$keys[$i]]) ? $this->_reduce_array($array[$keys[$i]], $keys, ($i+1)) : NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 }
Barry Mienydd671972010-10-04 16:33:58 +0200416
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 return $array;
418 }
419
420 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200421
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 /**
423 * Re-populate the _POST array with our finalized and processed data
424 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 * @return null
Barry Mienydd671972010-10-04 16:33:58 +0200426 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100427 protected function _reset_post_array()
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 {
429 foreach ($this->_field_data as $field => $row)
430 {
431 if ( ! is_null($row['postdata']))
432 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200433 if ($row['is_array'] === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 {
435 if (isset($_POST[$row['field']]))
436 {
437 $_POST[$row['field']] = $this->prep_for_form($row['postdata']);
438 }
439 }
440 else
441 {
Derek Jones63eeae32009-02-10 19:08:56 +0000442 // start with a reference
443 $post_ref =& $_POST;
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Jones63eeae32009-02-10 19:08:56 +0000445 // before we assign values, make a reference to the right POST key
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200446 if (count($row['keys']) === 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
Derek Jones63eeae32009-02-10 19:08:56 +0000448 $post_ref =& $post_ref[current($row['keys'])];
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 }
450 else
451 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 foreach ($row['keys'] as $val)
453 {
Derek Jones63eeae32009-02-10 19:08:56 +0000454 $post_ref =& $post_ref[$val];
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 }
456 }
Derek Jones63eeae32009-02-10 19:08:56 +0000457
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 if (is_array($row['postdata']))
Derek Jones63eeae32009-02-10 19:08:56 +0000459 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 $array = array();
461 foreach ($row['postdata'] as $k => $v)
462 {
463 $array[$k] = $this->prep_for_form($v);
464 }
Derek Jones63eeae32009-02-10 19:08:56 +0000465
466 $post_ref = $array;
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 }
468 else
Derek Jones63eeae32009-02-10 19:08:56 +0000469 {
470 $post_ref = $this->prep_for_form($row['postdata']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 }
473 }
474 }
475 }
476
477 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200478
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 /**
480 * Executes the Validation routines
481 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 * @param array
483 * @param array
484 * @param mixed
485 * @param integer
486 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200487 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100488 protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 {
490 // If the $_POST data is an array we will run a recursive call
491 if (is_array($postdata))
Barry Mienydd671972010-10-04 16:33:58 +0200492 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 foreach ($postdata as $key => $val)
494 {
495 $this->_execute($row, $rules, $val, $cycles);
496 $cycles++;
497 }
Barry Mienydd671972010-10-04 16:33:58 +0200498
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 return;
500 }
Barry Mienydd671972010-10-04 16:33:58 +0200501
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 // --------------------------------------------------------------------
503
504 // If the field is blank, but NOT required, no further tests are necessary
505 $callback = FALSE;
506 if ( ! in_array('required', $rules) AND is_null($postdata))
507 {
508 // Before we bail out, does the rule contain a callback?
Marcos Coelhoc28b2852011-07-05 12:59:41 -0700509 if (preg_match("/(callback_\w+(\[.*?\])?)/", implode(' ', $rules), $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 {
511 $callback = TRUE;
512 $rules = (array('1' => $match[1]));
513 }
514 else
515 {
516 return;
517 }
518 }
519
520 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200521
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 // Isset Test. Typically this rule will only apply to checkboxes.
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200523 if (is_null($postdata) AND $callback === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 {
525 if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
526 {
527 // Set the message type
528 $type = (in_array('required', $rules)) ? 'required' : 'isset';
Barry Mienydd671972010-10-04 16:33:58 +0200529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 if ( ! isset($this->_error_messages[$type]))
531 {
532 if (FALSE === ($line = $this->CI->lang->line($type)))
533 {
534 $line = 'The field was not set';
Barry Mienydd671972010-10-04 16:33:58 +0200535 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 }
537 else
538 {
539 $line = $this->_error_messages[$type];
540 }
Barry Mienydd671972010-10-04 16:33:58 +0200541
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 // Build the error message
543 $message = sprintf($line, $this->_translate_fieldname($row['label']));
544
545 // Save the error message
546 $this->_field_data[$row['field']]['error'] = $message;
Barry Mienydd671972010-10-04 16:33:58 +0200547
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 if ( ! isset($this->_error_array[$row['field']]))
549 {
550 $this->_error_array[$row['field']] = $message;
551 }
552 }
Barry Mienydd671972010-10-04 16:33:58 +0200553
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 return;
555 }
556
557 // --------------------------------------------------------------------
558
559 // Cycle through each rule and run it
560 foreach ($rules As $rule)
561 {
562 $_in_array = FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200563
Derek Allard2067d1a2008-11-13 22:59:24 +0000564 // We set the $postdata variable with the current data in our master array so that
565 // each cycle of the loop is dealing with the processed data from the last cycle
566 if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata']))
567 {
568 // We shouldn't need this safety, but just in case there isn't an array index
569 // associated with this cycle we'll bail out
570 if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles]))
571 {
572 continue;
573 }
Barry Mienydd671972010-10-04 16:33:58 +0200574
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 $postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
576 $_in_array = TRUE;
577 }
578 else
579 {
580 $postdata = $this->_field_data[$row['field']]['postdata'];
581 }
582
583 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200584
585 // Is the rule a callback?
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 $callback = FALSE;
587 if (substr($rule, 0, 9) == 'callback_')
588 {
589 $rule = substr($rule, 9);
590 $callback = TRUE;
591 }
Barry Mienydd671972010-10-04 16:33:58 +0200592
Derek Allard2067d1a2008-11-13 22:59:24 +0000593 // Strip the parameter (if exists) from the rule
594 // Rules can contain a parameter: max_length[5]
595 $param = FALSE;
Dan Horrigan2280e8e2010-12-15 10:16:38 -0500596 if (preg_match("/(.*?)\[(.*)\]/", $rule, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000597 {
598 $rule = $match[1];
599 $param = $match[2];
600 }
Barry Mienydd671972010-10-04 16:33:58 +0200601
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 // Call the function that corresponds to the rule
603 if ($callback === TRUE)
604 {
605 if ( ! method_exists($this->CI, $rule))
Barry Mienydd671972010-10-04 16:33:58 +0200606 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000607 continue;
608 }
Barry Mienydd671972010-10-04 16:33:58 +0200609
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 // Run the function and grab the result
611 $result = $this->CI->$rule($postdata, $param);
612
613 // Re-assign the result to the master data array
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200614 if ($_in_array === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000615 {
616 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
617 }
618 else
619 {
620 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
621 }
Barry Mienydd671972010-10-04 16:33:58 +0200622
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 // If the field isn't required and we just processed a callback we'll move on...
624 if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE)
625 {
Derek Allard4e5cf1c2009-07-06 20:53:41 +0000626 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 }
628 }
629 else
Barry Mienydd671972010-10-04 16:33:58 +0200630 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 if ( ! method_exists($this, $rule))
632 {
Barry Mienydd671972010-10-04 16:33:58 +0200633 // If our own wrapper function doesn't exist we see if a native PHP function does.
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 // Users can use any native PHP function call that has one param.
635 if (function_exists($rule))
636 {
637 $result = $rule($postdata);
Barry Mienydd671972010-10-04 16:33:58 +0200638
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200639 if ($_in_array === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 {
641 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
642 }
643 else
644 {
645 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
646 }
647 }
patwork02404a12011-04-08 15:45:46 +0200648 else
649 {
650 log_message('debug', "Unable to find validation rule: ".$rule);
651 }
Barry Mienydd671972010-10-04 16:33:58 +0200652
Derek Allard2067d1a2008-11-13 22:59:24 +0000653 continue;
654 }
655
656 $result = $this->$rule($postdata, $param);
657
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200658 if ($_in_array === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 {
660 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
661 }
662 else
663 {
664 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
665 }
666 }
Barry Mienydd671972010-10-04 16:33:58 +0200667
Derek Jones37f4b9c2011-07-01 17:56:50 -0500668 // Did the rule test negatively? If so, grab the error.
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 if ($result === FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200670 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000671 if ( ! isset($this->_error_messages[$rule]))
672 {
673 if (FALSE === ($line = $this->CI->lang->line($rule)))
674 {
675 $line = 'Unable to access an error message corresponding to your field name.';
Barry Mienydd671972010-10-04 16:33:58 +0200676 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000677 }
678 else
679 {
680 $line = $this->_error_messages[$rule];
681 }
Barry Mienydd671972010-10-04 16:33:58 +0200682
Derek Allard2067d1a2008-11-13 22:59:24 +0000683 // Is the parameter we are inserting into the error message the name
Derek Jones37f4b9c2011-07-01 17:56:50 -0500684 // of another field? If so we need to grab its "field label"
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200685 if (isset($this->_field_data[$param], $this->_field_data[$param]['label']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000686 {
Pascal Krietec1895832009-10-13 12:56:43 +0000687 $param = $this->_translate_fieldname($this->_field_data[$param]['label']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000688 }
Barry Mienydd671972010-10-04 16:33:58 +0200689
Derek Allard2067d1a2008-11-13 22:59:24 +0000690 // Build the error message
691 $message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
692
693 // Save the error message
694 $this->_field_data[$row['field']]['error'] = $message;
Barry Mienydd671972010-10-04 16:33:58 +0200695
Derek Allard2067d1a2008-11-13 22:59:24 +0000696 if ( ! isset($this->_error_array[$row['field']]))
697 {
698 $this->_error_array[$row['field']] = $message;
699 }
Barry Mienydd671972010-10-04 16:33:58 +0200700
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 return;
702 }
703 }
704 }
705
706 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200707
Derek Allard2067d1a2008-11-13 22:59:24 +0000708 /**
709 * Translate a field name
710 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000711 * @param string the field name
712 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200713 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100714 protected function _translate_fieldname($fieldname)
Derek Allard2067d1a2008-11-13 22:59:24 +0000715 {
716 // Do we need to translate the field name?
717 // We look for the prefix lang: to determine this
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200718 if (substr($fieldname, 0, 5) === 'lang:')
Derek Allard2067d1a2008-11-13 22:59:24 +0000719 {
720 // Grab the variable
Barry Mienydd671972010-10-04 16:33:58 +0200721 $line = substr($fieldname, 5);
722
Derek Jones37f4b9c2011-07-01 17:56:50 -0500723 // Were we able to translate the field name? If not we use $line
Derek Allard2067d1a2008-11-13 22:59:24 +0000724 if (FALSE === ($fieldname = $this->CI->lang->line($line)))
725 {
726 return $line;
727 }
728 }
729
730 return $fieldname;
731 }
732
733 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200734
Derek Allard2067d1a2008-11-13 22:59:24 +0000735 /**
736 * Get the value from a form
737 *
738 * Permits you to repopulate a form field with the value it was submitted
739 * with, or, if that value doesn't exist, with the default
740 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000741 * @param string the field name
742 * @param string
Andrey Andreev46ac8812012-02-28 14:32:54 +0200743 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200744 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100745 public function set_value($field = '', $default = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200747 if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000748 {
749 return $default;
750 }
Barry Mienydd671972010-10-04 16:33:58 +0200751
Phil Sturgeon5c561802011-01-05 16:31:59 +0000752 // If the data is an array output them one at a time.
Greg Aker03abee32011-12-25 00:31:29 -0600753 // E.g: form_input('name[]', set_value('name[]');
Phil Sturgeon5c561802011-01-05 16:31:59 +0000754 if (is_array($this->_field_data[$field]['postdata']))
755 {
756 return array_shift($this->_field_data[$field]['postdata']);
757 }
Phil Sturgeonc3828712011-01-19 12:31:47 +0000758
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 return $this->_field_data[$field]['postdata'];
760 }
Barry Mienydd671972010-10-04 16:33:58 +0200761
Derek Allard2067d1a2008-11-13 22:59:24 +0000762 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200763
Derek Allard2067d1a2008-11-13 22:59:24 +0000764 /**
765 * Set Select
766 *
767 * Enables pull-down lists to be set to the value the user
768 * selected in the event of an error
769 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000770 * @param string
771 * @param string
772 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200773 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100774 public function set_select($field = '', $value = '', $default = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200775 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200776 if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000777 {
Andrey Andreev0adff1b2012-02-28 14:36:40 +0200778 return ($default === TRUE && count($this->_field_data) === 0) ? ' selected="selected"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000779 }
Barry Mienydd671972010-10-04 16:33:58 +0200780
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 $field = $this->_field_data[$field]['postdata'];
Barry Mienydd671972010-10-04 16:33:58 +0200782
Derek Allard2067d1a2008-11-13 22:59:24 +0000783 if (is_array($field))
784 {
785 if ( ! in_array($value, $field))
786 {
787 return '';
788 }
789 }
Andrey Andreev46ac8812012-02-28 14:32:54 +0200790 elseif (($field == '' OR $value == '') OR ($field != $value))
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200792 return '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000793 }
Barry Mienydd671972010-10-04 16:33:58 +0200794
Derek Allard2067d1a2008-11-13 22:59:24 +0000795 return ' selected="selected"';
796 }
Barry Mienydd671972010-10-04 16:33:58 +0200797
Derek Allard2067d1a2008-11-13 22:59:24 +0000798 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200799
Derek Allard2067d1a2008-11-13 22:59:24 +0000800 /**
801 * Set Radio
802 *
803 * Enables radio buttons to be set to the value the user
804 * selected in the event of an error
805 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 * @param string
807 * @param string
808 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200809 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100810 public function set_radio($field = '', $value = '', $default = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000811 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200812 if ( ! isset($this->_field_data[$field], $this->_field_data[$field]['postdata']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000813 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200814 return ($default === TRUE && count($this->_field_data) === 0) ? ' checked="checked"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 }
Barry Mienydd671972010-10-04 16:33:58 +0200816
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 $field = $this->_field_data[$field]['postdata'];
Barry Mienydd671972010-10-04 16:33:58 +0200818
Derek Allard2067d1a2008-11-13 22:59:24 +0000819 if (is_array($field))
820 {
821 if ( ! in_array($value, $field))
822 {
823 return '';
824 }
825 }
826 else
827 {
828 if (($field == '' OR $value == '') OR ($field != $value))
829 {
830 return '';
831 }
832 }
Barry Mienydd671972010-10-04 16:33:58 +0200833
Derek Allard2067d1a2008-11-13 22:59:24 +0000834 return ' checked="checked"';
835 }
Barry Mienydd671972010-10-04 16:33:58 +0200836
Derek Allard2067d1a2008-11-13 22:59:24 +0000837 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200838
Derek Allard2067d1a2008-11-13 22:59:24 +0000839 /**
840 * Set Checkbox
841 *
842 * Enables checkboxes to be set to the value the user
843 * selected in the event of an error
844 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000845 * @param string
846 * @param string
847 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200848 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100849 public function set_checkbox($field = '', $value = '', $default = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000850 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200851 // Logic is exactly the same as for radio fields
852 return $this->set_radio($field, $value, $default);
Derek Allard2067d1a2008-11-13 22:59:24 +0000853 }
Barry Mienydd671972010-10-04 16:33:58 +0200854
Derek Allard2067d1a2008-11-13 22:59:24 +0000855 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200856
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 /**
858 * Required
859 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000860 * @param string
861 * @return bool
862 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100863 public function required($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200865 return ( ! is_array($str)) ? (trim($str) !== '') : ( ! empty($str));
Derek Allard2067d1a2008-11-13 22:59:24 +0000866 }
Barry Mienydd671972010-10-04 16:33:58 +0200867
Derek Allard2067d1a2008-11-13 22:59:24 +0000868 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200869
Derek Allard2067d1a2008-11-13 22:59:24 +0000870 /**
Dan Horrigan2280e8e2010-12-15 10:16:38 -0500871 * Performs a Regular Expression match test.
872 *
Dan Horrigan2280e8e2010-12-15 10:16:38 -0500873 * @param string
874 * @param regex
875 * @return bool
876 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100877 public function regex_match($str, $regex)
Dan Horrigan2280e8e2010-12-15 10:16:38 -0500878 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200879 return (bool) preg_match($regex, $str);
Dan Horrigan2280e8e2010-12-15 10:16:38 -0500880 }
881
882 // --------------------------------------------------------------------
883
884 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000885 * Match one field to another
886 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000887 * @param string
888 * @param field
889 * @return bool
890 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100891 public function matches($str, $field)
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 {
Andrey Andreevc8da4fe2012-03-04 19:20:33 +0200893 $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
JonoB099c4782012-03-04 14:37:30 +0000894 if ( ! isset($validation_array[$field]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000895 {
Barry Mienydd671972010-10-04 16:33:58 +0200896 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000897 }
Barry Mienydd671972010-10-04 16:33:58 +0200898
JonoB099c4782012-03-04 14:37:30 +0000899 return ($str === $validation_array[$field]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000900 }
Eric Barnescccde962011-12-04 00:01:17 -0500901
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100902 // --------------------------------------------------------------------
903
904 /**
Andrey Andreevd09d6502012-01-03 06:38:33 +0200905 * Is Unique
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100906 *
Andrey Andreevd09d6502012-01-03 06:38:33 +0200907 * Check if the input value doesn't already exist
908 * in the specified database field.
909 *
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100910 * @param string
911 * @param field
912 * @return bool
913 */
914 public function is_unique($str, $field)
915 {
Eric Barnescccde962011-12-04 00:01:17 -0500916 list($table, $field) = explode('.', $field);
917 if (isset($this->CI->db))
918 {
919 $query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
920 return $query->num_rows() === 0;
921 }
922 return FALSE;
Greg Aker03abee32011-12-25 00:31:29 -0600923 }
Barry Mienydd671972010-10-04 16:33:58 +0200924
Derek Allard2067d1a2008-11-13 22:59:24 +0000925 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200926
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 /**
928 * Minimum Length
929 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000930 * @param string
931 * @param value
932 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200933 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100934 public function min_length($str, $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000935 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200936 if (preg_match('/[^0-9]/', $val))
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 {
938 return FALSE;
939 }
940
941 if (function_exists('mb_strlen'))
942 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200943 return ! (mb_strlen($str) < $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 }
Barry Mienydd671972010-10-04 16:33:58 +0200945
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200946 return ! (strlen($str) < $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000947 }
Barry Mienydd671972010-10-04 16:33:58 +0200948
Derek Allard2067d1a2008-11-13 22:59:24 +0000949 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200950
Derek Allard2067d1a2008-11-13 22:59:24 +0000951 /**
952 * Max Length
953 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000954 * @param string
955 * @param value
956 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200957 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100958 public function max_length($str, $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000959 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200960 if (preg_match('/[^0-9]/', $val))
Derek Allard2067d1a2008-11-13 22:59:24 +0000961 {
962 return FALSE;
963 }
964
965 if (function_exists('mb_strlen'))
966 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200967 return ! (mb_strlen($str) > $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000968 }
Barry Mienydd671972010-10-04 16:33:58 +0200969
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200970 return ! (strlen($str) > $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 }
Barry Mienydd671972010-10-04 16:33:58 +0200972
Derek Allard2067d1a2008-11-13 22:59:24 +0000973 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200974
Derek Allard2067d1a2008-11-13 22:59:24 +0000975 /**
976 * Exact Length
977 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000978 * @param string
979 * @param value
980 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200981 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +0100982 public function exact_length($str, $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000983 {
Andrey Andreev46ac8812012-02-28 14:32:54 +0200984 if (preg_match('/[^0-9]/', $val))
Derek Allard2067d1a2008-11-13 22:59:24 +0000985 {
986 return FALSE;
987 }
988
989 if (function_exists('mb_strlen'))
990 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200991 return (mb_strlen($str) == $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000992 }
Barry Mienydd671972010-10-04 16:33:58 +0200993
Andrey Andreev8dc532d2011-12-24 17:57:54 +0200994 return (strlen($str) == $val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000995 }
Barry Mienydd671972010-10-04 16:33:58 +0200996
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200998
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 /**
1000 * Valid Email
1001 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001002 * @param string
1003 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001004 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001005 public function valid_email($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001006 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001007 return (bool) preg_match('/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001008 }
1009
1010 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001011
Derek Allard2067d1a2008-11-13 22:59:24 +00001012 /**
1013 * Valid Emails
1014 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001015 * @param string
1016 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001017 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001018 public function valid_emails($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001019 {
1020 if (strpos($str, ',') === FALSE)
1021 {
1022 return $this->valid_email(trim($str));
1023 }
Barry Mienydd671972010-10-04 16:33:58 +02001024
Pascal Kriete14287f32011-02-14 13:39:34 -05001025 foreach (explode(',', $str) as $email)
Derek Allard2067d1a2008-11-13 22:59:24 +00001026 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001027 if (trim($email) !== '' && $this->valid_email(trim($email)) === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001028 {
1029 return FALSE;
1030 }
1031 }
Barry Mienydd671972010-10-04 16:33:58 +02001032
Derek Allard2067d1a2008-11-13 22:59:24 +00001033 return TRUE;
1034 }
1035
1036 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001037
Derek Allard2067d1a2008-11-13 22:59:24 +00001038 /**
1039 * Validate IP Address
1040 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001041 * @param string
Bo-Yi Wu013c8952011-09-12 15:03:44 +08001042 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +00001043 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001044 public function valid_ip($ip)
Derek Allard2067d1a2008-11-13 22:59:24 +00001045 {
1046 return $this->CI->input->valid_ip($ip);
1047 }
1048
1049 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001050
Derek Allard2067d1a2008-11-13 22:59:24 +00001051 /**
1052 * Alpha
1053 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001054 * @param string
1055 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001056 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001057 public function alpha($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001058 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001059 return (bool) preg_match('/^[a-z]+$/i', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001060 }
Barry Mienydd671972010-10-04 16:33:58 +02001061
Derek Allard2067d1a2008-11-13 22:59:24 +00001062 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001063
Derek Allard2067d1a2008-11-13 22:59:24 +00001064 /**
1065 * Alpha-numeric
1066 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001067 * @param string
1068 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001069 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001070 public function alpha_numeric($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001071 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001072 return (bool) preg_match('/^[a-z0-9]+$/i', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001073 }
Barry Mienydd671972010-10-04 16:33:58 +02001074
Derek Allard2067d1a2008-11-13 22:59:24 +00001075 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001076
Derek Allard2067d1a2008-11-13 22:59:24 +00001077 /**
1078 * Alpha-numeric with underscores and dashes
1079 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001080 * @param string
1081 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001082 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001083 public function alpha_dash($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001084 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001085 return (bool) preg_match('/^[a-z0-9_-]+$/i', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001086 }
Barry Mienydd671972010-10-04 16:33:58 +02001087
Derek Allard2067d1a2008-11-13 22:59:24 +00001088 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001089
Derek Allard2067d1a2008-11-13 22:59:24 +00001090 /**
1091 * Numeric
1092 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001093 * @param string
1094 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001095 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001096 public function numeric($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001097 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001098 return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001099
1100 }
1101
1102 // --------------------------------------------------------------------
1103
Barry Mienydd671972010-10-04 16:33:58 +02001104 /**
1105 * Is Numeric
1106 *
Barry Mienydd671972010-10-04 16:33:58 +02001107 * @param string
1108 * @return bool
1109 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001110 public function is_numeric($str)
Barry Mienydd671972010-10-04 16:33:58 +02001111 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001112 return is_numeric($str);
Barry Mienydd671972010-10-04 16:33:58 +02001113 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001114
1115 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001116
Derek Allard2067d1a2008-11-13 22:59:24 +00001117 /**
1118 * Integer
1119 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001120 * @param string
1121 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +02001122 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001123 public function integer($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 {
Phil Sturgeonef112c02011-02-07 13:01:47 +00001125 return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
1126 }
1127
1128 // --------------------------------------------------------------------
1129
1130 /**
1131 * Decimal number
1132 *
Phil Sturgeonef112c02011-02-07 13:01:47 +00001133 * @param string
1134 * @return bool
1135 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001136 public function decimal($str)
Phil Sturgeonef112c02011-02-07 13:01:47 +00001137 {
1138 return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str);
1139 }
1140
1141 // --------------------------------------------------------------------
1142
1143 /**
Nick Busey98c347d2012-02-02 11:07:03 -07001144 * Greater than
Phil Sturgeonef112c02011-02-07 13:01:47 +00001145 *
Phil Sturgeonef112c02011-02-07 13:01:47 +00001146 * @param string
1147 * @return bool
1148 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001149 public function greater_than($str, $min)
Phil Sturgeonef112c02011-02-07 13:01:47 +00001150 {
1151 if ( ! is_numeric($str))
1152 {
Pascal Kriete8761ef52011-02-14 13:13:52 -05001153 return FALSE;
Phil Sturgeonef112c02011-02-07 13:01:47 +00001154 }
1155 return $str > $min;
1156 }
1157
1158 // --------------------------------------------------------------------
Nick Busey98c347d2012-02-02 11:07:03 -07001159
1160 /**
1161 * Equal to or Greater than
1162 *
1163 * @access public
1164 * @param string
1165 * @return bool
1166 */
Nick Buseyc1931662012-02-06 17:55:58 -07001167 function greater_than_equal_to($str, $min)
Nick Busey98c347d2012-02-02 11:07:03 -07001168 {
1169 if ( ! is_numeric($str))
1170 {
1171 return FALSE;
1172 }
1173 return $str >= $min;
1174 }
1175
1176 // --------------------------------------------------------------------
Phil Sturgeonef112c02011-02-07 13:01:47 +00001177
1178 /**
1179 * Less than
1180 *
Phil Sturgeonef112c02011-02-07 13:01:47 +00001181 * @param string
1182 * @return bool
1183 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001184 public function less_than($str, $max)
Phil Sturgeonef112c02011-02-07 13:01:47 +00001185 {
1186 if ( ! is_numeric($str))
1187 {
Pascal Kriete8761ef52011-02-14 13:13:52 -05001188 return FALSE;
Phil Sturgeonef112c02011-02-07 13:01:47 +00001189 }
1190 return $str < $max;
Derek Allard2067d1a2008-11-13 22:59:24 +00001191 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001192
1193 // --------------------------------------------------------------------
1194
Barry Mienydd671972010-10-04 16:33:58 +02001195 /**
Nick Busey98c347d2012-02-02 11:07:03 -07001196 * Equal to or Less than
1197 *
1198 * @access public
1199 * @param string
1200 * @return bool
1201 */
Nick Buseyc1931662012-02-06 17:55:58 -07001202 function less_than_equal_to($str, $max)
Nick Busey98c347d2012-02-02 11:07:03 -07001203 {
1204 if ( ! is_numeric($str))
1205 {
1206 return FALSE;
1207 }
1208 return $str <= $max;
1209 }
1210
1211 // --------------------------------------------------------------------
1212
1213 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001214 * Is a Natural number (0,1,2,3, etc.)
Barry Mienydd671972010-10-04 16:33:58 +02001215 *
Barry Mienydd671972010-10-04 16:33:58 +02001216 * @param string
1217 * @return bool
1218 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001219 public function is_natural($str)
Barry Mienydd671972010-10-04 16:33:58 +02001220 {
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001221 return (bool) preg_match('/^[0-9]+$/', $str);
Barry Mienydd671972010-10-04 16:33:58 +02001222 }
1223
1224 // --------------------------------------------------------------------
1225
1226 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -05001227 * Is a Natural number, but not a zero (1,2,3, etc.)
Barry Mienydd671972010-10-04 16:33:58 +02001228 *
Barry Mienydd671972010-10-04 16:33:58 +02001229 * @param string
1230 * @return bool
1231 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001232 public function is_natural_no_zero($str)
Barry Mienydd671972010-10-04 16:33:58 +02001233 {
Andrey Andreev46ac8812012-02-28 14:32:54 +02001234 return ($str != 0 && preg_match('/^[0-9]+$/', $str));
Barry Mienydd671972010-10-04 16:33:58 +02001235 }
1236
Derek Allard2067d1a2008-11-13 22:59:24 +00001237 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001238
Derek Allard2067d1a2008-11-13 22:59:24 +00001239 /**
1240 * Valid Base64
1241 *
1242 * Tests a string for characters outside of the Base64 alphabet
1243 * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
1244 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001245 * @param string
1246 * @return bool
1247 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001248 public function valid_base64($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001249 {
1250 return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
1251 }
Barry Mienydd671972010-10-04 16:33:58 +02001252
Derek Allard2067d1a2008-11-13 22:59:24 +00001253 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001254
Derek Allard2067d1a2008-11-13 22:59:24 +00001255 /**
1256 * Prep data for form
1257 *
1258 * This function allows HTML to be safely shown in a form.
1259 * Special characters are converted.
1260 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001261 * @param string
1262 * @return string
1263 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001264 public function prep_for_form($data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001265 {
1266 if (is_array($data))
1267 {
1268 foreach ($data as $key => $val)
1269 {
1270 $data[$key] = $this->prep_for_form($val);
1271 }
Barry Mienydd671972010-10-04 16:33:58 +02001272
Derek Allard2067d1a2008-11-13 22:59:24 +00001273 return $data;
1274 }
Barry Mienydd671972010-10-04 16:33:58 +02001275
Derek Allard2067d1a2008-11-13 22:59:24 +00001276 if ($this->_safe_form_data == FALSE OR $data === '')
1277 {
1278 return $data;
1279 }
1280
Andrey Andreev46ac8812012-02-28 14:32:54 +02001281 return str_replace(array("'", '"', '<', '>'), array('&#39;', '&quot;', '&lt;', '&gt;'), stripslashes($data));
Derek Allard2067d1a2008-11-13 22:59:24 +00001282 }
Barry Mienydd671972010-10-04 16:33:58 +02001283
Derek Allard2067d1a2008-11-13 22:59:24 +00001284 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001285
Derek Allard2067d1a2008-11-13 22:59:24 +00001286 /**
1287 * Prep URL
1288 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001289 * @param string
1290 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001291 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001292 public function prep_url($str = '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001293 {
1294 if ($str == 'http://' OR $str == '')
1295 {
1296 return '';
1297 }
Barry Mienydd671972010-10-04 16:33:58 +02001298
Andrey Andreev8dc532d2011-12-24 17:57:54 +02001299 if (substr($str, 0, 7) !== 'http://' && substr($str, 0, 8) !== 'https://')
Derek Allard2067d1a2008-11-13 22:59:24 +00001300 {
1301 $str = 'http://'.$str;
1302 }
Barry Mienydd671972010-10-04 16:33:58 +02001303
Derek Allard2067d1a2008-11-13 22:59:24 +00001304 return $str;
1305 }
Barry Mienydd671972010-10-04 16:33:58 +02001306
Derek Allard2067d1a2008-11-13 22:59:24 +00001307 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001308
Derek Allard2067d1a2008-11-13 22:59:24 +00001309 /**
1310 * Strip Image Tags
1311 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001312 * @param string
1313 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001314 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001315 public function strip_image_tags($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001316 {
1317 return $this->CI->input->strip_image_tags($str);
1318 }
Barry Mienydd671972010-10-04 16:33:58 +02001319
Derek Allard2067d1a2008-11-13 22:59:24 +00001320 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001321
Derek Allard2067d1a2008-11-13 22:59:24 +00001322 /**
1323 * XSS Clean
1324 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001325 * @param string
1326 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001327 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001328 public function xss_clean($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001329 {
Derek Jones5640a712010-04-23 11:22:40 -05001330 return $this->CI->security->xss_clean($str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001331 }
Barry Mienydd671972010-10-04 16:33:58 +02001332
Derek Allard2067d1a2008-11-13 22:59:24 +00001333 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001334
Derek Allard2067d1a2008-11-13 22:59:24 +00001335 /**
1336 * Convert PHP tags to entities
1337 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001338 * @param string
1339 * @return string
Barry Mienydd671972010-10-04 16:33:58 +02001340 */
Phil Sturgeon3837ae72011-05-09 21:12:26 +01001341 public function encode_php_tags($str)
Derek Allard2067d1a2008-11-13 22:59:24 +00001342 {
Derek Jones37f4b9c2011-07-01 17:56:50 -05001343 return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
Derek Allard2067d1a2008-11-13 22:59:24 +00001344 }
1345
JonoB099c4782012-03-04 14:37:30 +00001346 // --------------------------------------------------------------------
Andrey Andreevc8da4fe2012-03-04 19:20:33 +02001347
1348 /**
1349 * Reset validation vars
1350 *
1351 * Prevents subsequent validation routines from being affected by the
JonoB099c4782012-03-04 14:37:30 +00001352 * results of any previous validation routine due to the CI singleton.
Andrey Andreevc8da4fe2012-03-04 19:20:33 +02001353 *
1354 * @return void
1355 */
JonoB883f80f2012-03-05 09:51:27 +00001356 public function reset_validation()
Andrey Andreevc8da4fe2012-03-04 19:20:33 +02001357 {
JonoB099c4782012-03-04 14:37:30 +00001358 $this->_field_data = array();
1359 $this->_config_rules = array();
1360 $this->_error_array = array();
1361 $this->_error_messages = array();
1362 $this->error_string = '';
Andrey Andreevc8da4fe2012-03-04 19:20:33 +02001363 }
1364
Derek Allard2067d1a2008-11-13 22:59:24 +00001365}
Derek Allard2067d1a2008-11-13 22:59:24 +00001366
1367/* End of file Form_validation.php */
Marcos Coelhoc28b2852011-07-05 12:59:41 -07001368/* Location: ./system/libraries/Form_validation.php */