Take two:
[www-register-wizard.git] / libraries / Validation.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\r
7  * @package             CodeIgniter\r
8  * @author              ExpressionEngine Dev Team\r
9  * @copyright   Copyright (c) 2008, EllisLab, Inc.\r
10  * @license             http://codeigniter.com/user_guide/license.html\r
11  * @link                http://codeigniter.com\r
12  * @since               Version 1.0\r
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * Validation Class\r
20  *\r
21  * @package             CodeIgniter\r
22  * @subpackage  Libraries\r
23  * @category    Validation\r
24  * @author              ExpressionEngine Dev Team\r
25  * @link                http://codeigniter.com/user_guide/libraries/validation.html\r
26  */\r
27 class CI_Validation {\r
28         \r
29         var $CI;\r
30         var $error_string               = '';\r
31         var $_error_array               = array();\r
32         var $_rules                             = array();\r
33         var $_fields                    = array();\r
34         var $_error_messages    = array();\r
35         var $_current_field     = '';\r
36         var $_safe_form_data    = FALSE;\r
37         var $_error_prefix              = '<p>';\r
38         var $_error_suffix              = '</p>';\r
39 \r
40         \r
41 \r
42         /**\r
43          * Constructor\r
44          *\r
45          */     \r
46         function CI_Validation()\r
47         {       \r
48                 $this->CI =& get_instance();\r
49                 \r
50                 if (function_exists('mb_internal_encoding'))\r
51                 {\r
52                         mb_internal_encoding($this->CI->config->item('charset'));\r
53                 }\r
54                 \r
55                 log_message('debug', "Validation Class Initialized");\r
56         }\r
57         \r
58         // --------------------------------------------------------------------\r
59         \r
60         /**\r
61          * Set Fields\r
62          *\r
63          * This function takes an array of field names as input\r
64          * and generates class variables with the same name, which will\r
65          * either be blank or contain the $_POST value corresponding to it\r
66          *\r
67          * @access      public\r
68          * @param       string\r
69          * @param       string\r
70          * @return      void\r
71          */\r
72         function set_fields($data = '', $field = '')\r
73         {       \r
74                 if ($data == '')\r
75                 {\r
76                         if (count($this->_fields) == 0)\r
77                         {\r
78                                 return FALSE;\r
79                         }\r
80                 }\r
81                 else\r
82                 {\r
83                         if ( ! is_array($data))\r
84                         {\r
85                                 $data = array($data => $field);\r
86                         }\r
87                         \r
88                         if (count($data) > 0)\r
89                         {\r
90                                 $this->_fields = $data;\r
91                         }\r
92                 }               \r
93                         \r
94                 foreach($this->_fields as $key => $val)\r
95                 {\r
96                         $this->$key = ( ! isset($_POST[$key])) ? '' : $this->prep_for_form($_POST[$key]);\r
97                         \r
98                         $error = $key.'_error';\r
99                         if ( ! isset($this->$error))\r
100                         {\r
101                                 $this->$error = '';\r
102                         }\r
103                 }               \r
104         }\r
105         \r
106         // --------------------------------------------------------------------\r
107         \r
108         /**\r
109          * Set Rules\r
110          *\r
111          * This function takes an array of field names and validation\r
112          * rules as input ad simply stores is for use later.\r
113          *\r
114          * @access      public\r
115          * @param       mixed\r
116          * @param       string\r
117          * @return      void\r
118          */\r
119         function set_rules($data, $rules = '')\r
120         {\r
121                 if ( ! is_array($data))\r
122                 {\r
123                         if ($rules == '')\r
124                                 return;\r
125                                 \r
126                         $data = array($data => $rules);\r
127                 }\r
128         \r
129                 foreach ($data as $key => $val)\r
130                 {\r
131                         $this->_rules[$key] = $val;\r
132                 }\r
133         }\r
134         \r
135         // --------------------------------------------------------------------\r
136         \r
137         /**\r
138          * Set Error Message\r
139          *\r
140          * Lets users set their own error messages on the fly.  Note:  The key\r
141          * name has to match the  function name that it corresponds to.\r
142          *\r
143          * @access      public\r
144          * @param       string\r
145          * @param       string\r
146          * @return      string\r
147          */\r
148         function set_message($lang, $val = '')\r
149         {\r
150                 if ( ! is_array($lang))\r
151                 {\r
152                         $lang = array($lang => $val);\r
153                 }\r
154         \r
155                 $this->_error_messages = array_merge($this->_error_messages, $lang);\r
156         }\r
157         \r
158         // --------------------------------------------------------------------\r
159         \r
160         /**\r
161          * Set The Error Delimiter\r
162          *\r
163          * Permits a prefix/suffix to be added to each error message\r
164          *\r
165          * @access      public\r
166          * @param       string\r
167          * @param       string\r
168          * @return      void\r
169          */     \r
170         function set_error_delimiters($prefix = '<p>', $suffix = '</p>')\r
171         {\r
172                 $this->_error_prefix = $prefix;\r
173                 $this->_error_suffix = $suffix;\r
174         }\r
175         \r
176         // --------------------------------------------------------------------\r
177         \r
178         /**\r
179          * Run the Validator\r
180          *\r
181          * This function does all the work.\r
182          *\r
183          * @access      public\r
184          * @return      bool\r
185          */             \r
186         function run()\r
187         {\r
188                 // Do we even have any data to process?  Mm?\r
189                 if (count($_POST) == 0 OR count($this->_rules) == 0)\r
190                 {\r
191                         return FALSE;\r
192                 }\r
193         \r
194                 // Load the language file containing error messages\r
195                 $this->CI->lang->load('validation');\r
196                                                         \r
197                 // Cycle through the rules and test for errors\r
198                 foreach ($this->_rules as $field => $rules)\r
199                 {\r
200                         //Explode out the rules!\r
201                         $ex = explode('|', $rules);\r
202 \r
203                         // Is the field required?  If not, if the field is blank  we'll move on to the next test\r
204                         if ( ! in_array('required', $ex, TRUE))\r
205                         {\r
206                                 if ( ! isset($_POST[$field]) OR $_POST[$field] == '')\r
207                                 {\r
208                                         continue;\r
209                                 }\r
210                         }\r
211                         \r
212                         /*\r
213                          * Are we dealing with an "isset" rule?\r
214                          *\r
215                          * Before going further, we'll see if one of the rules\r
216                          * is to check whether the item is set (typically this\r
217                          * applies only to checkboxes).  If so, we'll\r
218                          * test for it here since there's not reason to go\r
219                          * further\r
220                          */\r
221                         if ( ! isset($_POST[$field]))\r
222                         {                       \r
223                                 if (in_array('isset', $ex, TRUE) OR in_array('required', $ex))\r
224                                 {\r
225                                         if ( ! isset($this->_error_messages['isset']))\r
226                                         {\r
227                                                 if (FALSE === ($line = $this->CI->lang->line('isset')))\r
228                                                 {\r
229                                                         $line = 'The field was not set';\r
230                                                 }                                                       \r
231                                         }\r
232                                         else\r
233                                         {\r
234                                                 $line = $this->_error_messages['isset'];\r
235                                         }\r
236                                         \r
237                                         // Build the error message\r
238                                         $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];\r
239                                         $message = sprintf($line, $mfield);\r
240 \r
241                                         // Set the error variable.  Example: $this->username_error\r
242                                         $error = $field.'_error';\r
243                                         $this->$error = $this->_error_prefix.$message.$this->_error_suffix;\r
244                                         $this->_error_array[] = $message;\r
245                                 }\r
246                                                 \r
247                                 continue;\r
248                         }\r
249         \r
250                         /*\r
251                          * Set the current field\r
252                          *\r
253                          * The various prepping functions need to know the\r
254                          * current field name so they can do this:\r
255                          *\r
256                          * $_POST[$this->_current_field] == 'bla bla';\r
257                          */\r
258                         $this->_current_field = $field;\r
259 \r
260                         // Cycle through the rules!\r
261                         foreach ($ex As $rule)\r
262                         {\r
263                                 // Is the rule a callback?                      \r
264                                 $callback = FALSE;\r
265                                 if (substr($rule, 0, 9) == 'callback_')\r
266                                 {\r
267                                         $rule = substr($rule, 9);\r
268                                         $callback = TRUE;\r
269                                 }\r
270                                 \r
271                                 // Strip the parameter (if exists) from the rule\r
272                                 // Rules can contain a parameter: max_length[5]\r
273                                 $param = FALSE;\r
274                                 if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match))\r
275                                 {\r
276                                         $rule   = $match[1];\r
277                                         $param  = $match[2];\r
278                                 }\r
279                                 \r
280                                 // Call the function that corresponds to the rule\r
281                                 if ($callback === TRUE)\r
282                                 {\r
283                                         if ( ! method_exists($this->CI, $rule))\r
284                                         {               \r
285                                                 continue;\r
286                                         }\r
287                                         \r
288                                         $result = $this->CI->$rule($_POST[$field], $param);     \r
289                                         \r
290                                         // If the field isn't required and we just processed a callback we'll move on...\r
291                                         if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE)\r
292                                         {\r
293                                                 continue 2;\r
294                                         }\r
295                                         \r
296                                 }\r
297                                 else\r
298                                 {                               \r
299                                         if ( ! method_exists($this, $rule))\r
300                                         {\r
301                                                 /*\r
302                                                  * Run the native PHP function if called for\r
303                                                  *\r
304                                                  * If our own wrapper function doesn't exist we see\r
305                                                  * if a native PHP function does. Users can use\r
306                                                  * any native PHP function call that has one param.\r
307                                                  */\r
308                                                 if (function_exists($rule))\r
309                                                 {\r
310                                                         $_POST[$field] = $rule($_POST[$field]);\r
311                                                         $this->$field = $_POST[$field];\r
312                                                 }\r
313                                                                                         \r
314                                                 continue;\r
315                                         }\r
316                                         \r
317                                         $result = $this->$rule($_POST[$field], $param);\r
318                                 }\r
319                                                                 \r
320                                 // Did the rule test negatively?  If so, grab the error.\r
321                                 if ($result === FALSE)\r
322                                 {\r
323                                         if ( ! isset($this->_error_messages[$rule]))\r
324                                         {\r
325                                                 if (FALSE === ($line = $this->CI->lang->line($rule)))\r
326                                                 {\r
327                                                         $line = 'Unable to access an error message corresponding to your field name.';\r
328                                                 }                                               \r
329                                         }\r
330                                         else\r
331                                         {\r
332                                                 $line = $this->_error_messages[$rule];\r
333                                         }                               \r
334 \r
335                                         // Build the error message\r
336                                         $mfield = ( ! isset($this->_fields[$field])) ? $field : $this->_fields[$field];\r
337                                         $mparam = ( ! isset($this->_fields[$param])) ? $param : $this->_fields[$param];\r
338                                         $message = sprintf($line, $mfield, $mparam);\r
339                                         \r
340                                         // Set the error variable.  Example: $this->username_error\r
341                                         $error = $field.'_error';\r
342                                         $this->$error = $this->_error_prefix.$message.$this->_error_suffix;\r
343 \r
344                                         // Add the error to the error array\r
345                                         $this->_error_array[] = $message;                               \r
346                                         continue 2;\r
347                                 }                               \r
348                         }\r
349                         \r
350                 }\r
351                 \r
352                 $total_errors = count($this->_error_array);\r
353 \r
354                 /*\r
355                  * Recompile the class variables\r
356                  *\r
357                  * If any prepping functions were called the $_POST data\r
358                  * might now be different then the corresponding class\r
359                  * variables so we'll set them anew.\r
360                  */     \r
361                 if ($total_errors > 0)\r
362                 {\r
363                         $this->_safe_form_data = TRUE;\r
364                 }\r
365                 \r
366                 $this->set_fields();\r
367 \r
368                 // Did we end up with any errors?\r
369                 if ($total_errors == 0)\r
370                 {\r
371                         return TRUE;\r
372                 }\r
373                 \r
374                 // Generate the error string\r
375                 foreach ($this->_error_array as $val)\r
376                 {\r
377                         $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n";\r
378                 }\r
379 \r
380                 return FALSE;\r
381         }\r
382         \r
383         // --------------------------------------------------------------------\r
384         \r
385         /**\r
386          * Required\r
387          *\r
388          * @access      public\r
389          * @param       string\r
390          * @return      bool\r
391          */\r
392         function required($str)\r
393         {\r
394                 if ( ! is_array($str))\r
395                 {\r
396                         return (trim($str) == '') ? FALSE : TRUE;\r
397                 }\r
398                 else\r
399                 {\r
400                         return ( ! empty($str));\r
401                 }\r
402         }\r
403         \r
404         // --------------------------------------------------------------------\r
405         \r
406         /**\r
407          * Match one field to another\r
408          *\r
409          * @access      public\r
410          * @param       string\r
411          * @param       field\r
412          * @return      bool\r
413          */\r
414         function matches($str, $field)\r
415         {\r
416                 if ( ! isset($_POST[$field]))\r
417                 {\r
418                         return FALSE;\r
419                 }\r
420                 \r
421                 return ($str !== $_POST[$field]) ? FALSE : TRUE;\r
422         }\r
423         \r
424         // --------------------------------------------------------------------\r
425         \r
426         /**\r
427          * Minimum Length\r
428          *\r
429          * @access      public\r
430          * @param       string\r
431          * @param       value\r
432          * @return      bool\r
433          */     \r
434         function min_length($str, $val)\r
435         {\r
436                 if (preg_match("/[^0-9]/", $val))\r
437                 {\r
438                         return FALSE;\r
439                 }\r
440 \r
441                 if (function_exists('mb_strlen'))\r
442                 {\r
443                         return (mb_strlen($str) < $val) ? FALSE : TRUE;         \r
444                 }\r
445 \r
446                 return (strlen($str) < $val) ? FALSE : TRUE;\r
447         }\r
448         \r
449         // --------------------------------------------------------------------\r
450         \r
451         /**\r
452          * Max Length\r
453          *\r
454          * @access      public\r
455          * @param       string\r
456          * @param       value\r
457          * @return      bool\r
458          */     \r
459         function max_length($str, $val)\r
460         {\r
461                 if (preg_match("/[^0-9]/", $val))\r
462                 {\r
463                         return FALSE;\r
464                 }\r
465                 \r
466                 if (function_exists('mb_strlen'))\r
467                 {\r
468                         return (mb_strlen($str) > $val) ? FALSE : TRUE;         \r
469                 }\r
470 \r
471                 return (strlen($str) > $val) ? FALSE : TRUE;\r
472         }\r
473         \r
474         // --------------------------------------------------------------------\r
475         \r
476         /**\r
477          * Exact Length\r
478          *\r
479          * @access      public\r
480          * @param       string\r
481          * @param       value\r
482          * @return      bool\r
483          */     \r
484         function exact_length($str, $val)\r
485         {\r
486                 if (preg_match("/[^0-9]/", $val))\r
487                 {\r
488                         return FALSE;\r
489                 }\r
490         \r
491                 if (function_exists('mb_strlen'))\r
492                 {\r
493                         return (mb_strlen($str) != $val) ? FALSE : TRUE;                \r
494                 }\r
495 \r
496                 return (strlen($str) != $val) ? FALSE : TRUE;\r
497         }\r
498         \r
499         // --------------------------------------------------------------------\r
500         \r
501         /**\r
502          * Valid Email\r
503          *\r
504          * @access      public\r
505          * @param       string\r
506          * @return      bool\r
507          */     \r
508         function valid_email($str)\r
509         {\r
510                 return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;\r
511         }\r
512 \r
513         // --------------------------------------------------------------------\r
514         \r
515         /**\r
516          * Valid Emails\r
517          *\r
518          * @access      public\r
519          * @param       string\r
520          * @return      bool\r
521          */     \r
522         function valid_emails($str)\r
523         {\r
524                 if (strpos($str, ',') === FALSE)\r
525                 {\r
526                         return $this->valid_email(trim($str));\r
527                 }\r
528                 \r
529                 foreach(explode(',', $str) as $email)\r
530                 {\r
531                         if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE)\r
532                         {\r
533                                 return FALSE;\r
534                         }\r
535                 }\r
536                 \r
537                 return TRUE;\r
538         }\r
539 \r
540         // --------------------------------------------------------------------\r
541         \r
542         /**\r
543          * Validate IP Address\r
544          *\r
545          * @access      public\r
546          * @param       string\r
547          * @return      string\r
548          */\r
549         function valid_ip($ip)\r
550         {\r
551                 return $this->CI->input->valid_ip($ip);\r
552         }\r
553 \r
554         // --------------------------------------------------------------------\r
555         \r
556         /**\r
557          * Alpha\r
558          *\r
559          * @access      public\r
560          * @param       string\r
561          * @return      bool\r
562          */             \r
563         function alpha($str)\r
564         {\r
565                 return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;\r
566         }\r
567         \r
568         // --------------------------------------------------------------------\r
569         \r
570         /**\r
571          * Alpha-numeric\r
572          *\r
573          * @access      public\r
574          * @param       string\r
575          * @return      bool\r
576          */     \r
577         function alpha_numeric($str)\r
578         {\r
579                 return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;\r
580         }\r
581         \r
582         // --------------------------------------------------------------------\r
583         \r
584         /**\r
585          * Alpha-numeric with underscores and dashes\r
586          *\r
587          * @access      public\r
588          * @param       string\r
589          * @return      bool\r
590          */     \r
591         function alpha_dash($str)\r
592         {\r
593                 return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;\r
594         }\r
595         \r
596         // --------------------------------------------------------------------\r
597         \r
598         /**\r
599          * Numeric\r
600          *\r
601          * @access      public\r
602          * @param       string\r
603          * @return      bool\r
604          */     \r
605         function numeric($str)\r
606         {\r
607                 return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);\r
608 \r
609         }\r
610 \r
611         // --------------------------------------------------------------------\r
612 \r
613         /**\r
614          * Is Numeric\r
615          *\r
616          * @access      public\r
617          * @param       string\r
618          * @return      bool\r
619          */\r
620         function is_numeric($str)\r
621         {\r
622                 return ( ! is_numeric($str)) ? FALSE : TRUE;\r
623         } \r
624 \r
625         // --------------------------------------------------------------------\r
626         \r
627         /**\r
628          * Integer\r
629          *\r
630          * @access      public\r
631          * @param       string\r
632          * @return      bool\r
633          */     \r
634         function integer($str)\r
635         {\r
636                 return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);\r
637         }\r
638 \r
639         // --------------------------------------------------------------------\r
640 \r
641         /**\r
642          * Is a Natural number  (0,1,2,3, etc.)\r
643          *\r
644          * @access      public\r
645          * @param       string\r
646          * @return      bool\r
647          */\r
648         function is_natural($str)\r
649         {   \r
650                 return (bool)preg_match( '/^[0-9]+$/', $str);\r
651         }\r
652 \r
653         // --------------------------------------------------------------------\r
654 \r
655         /**\r
656          * Is a Natural number, but not a zero  (1,2,3, etc.)\r
657          *\r
658          * @access      public\r
659          * @param       string\r
660          * @return      bool\r
661          */\r
662         function is_natural_no_zero($str)\r
663         {   \r
664                 if ( ! preg_match( '/^[0-9]+$/', $str))\r
665                 {\r
666                         return FALSE;\r
667                 }\r
668         \r
669                 if ($str == 0)\r
670                 {\r
671                         return FALSE;\r
672                 }\r
673 \r
674                 return TRUE;\r
675         }\r
676 \r
677         // --------------------------------------------------------------------\r
678         \r
679         /**\r
680          * Valid Base64\r
681          *\r
682          * Tests a string for characters outside of the Base64 alphabet\r
683          * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045\r
684          *\r
685          * @access      public\r
686          * @param       string\r
687          * @return      bool\r
688          */\r
689         function valid_base64($str)\r
690         {\r
691                 return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);\r
692         }\r
693 \r
694         // --------------------------------------------------------------------\r
695         \r
696         /**\r
697          * Set Select\r
698          *\r
699          * Enables pull-down lists to be set to the value the user\r
700          * selected in the event of an error\r
701          *\r
702          * @access      public\r
703          * @param       string\r
704          * @param       string\r
705          * @return      string\r
706          */     \r
707         function set_select($field = '', $value = '')\r
708         {\r
709                 if ($field == '' OR $value == '' OR  ! isset($_POST[$field]))\r
710                 {\r
711                         return '';\r
712                 }\r
713                         \r
714                 if ($_POST[$field] == $value)\r
715                 {\r
716                         return ' selected="selected"';\r
717                 }\r
718         }\r
719         \r
720         // --------------------------------------------------------------------\r
721         \r
722         /**\r
723          * Set Radio\r
724          *\r
725          * Enables radio buttons to be set to the value the user\r
726          * selected in the event of an error\r
727          *\r
728          * @access      public\r
729          * @param       string\r
730          * @param       string\r
731          * @return      string\r
732          */     \r
733         function set_radio($field = '', $value = '')\r
734         {\r
735                 if ($field == '' OR $value == '' OR  ! isset($_POST[$field]))\r
736                 {\r
737                         return '';\r
738                 }\r
739                         \r
740                 if ($_POST[$field] == $value)\r
741                 {\r
742                         return ' checked="checked"';\r
743                 }\r
744         }\r
745         \r
746         // --------------------------------------------------------------------\r
747         \r
748         /**\r
749          * Set Checkbox\r
750          *\r
751          * Enables checkboxes to be set to the value the user\r
752          * selected in the event of an error\r
753          *\r
754          * @access      public\r
755          * @param       string\r
756          * @param       string\r
757          * @return      string\r
758          */     \r
759         function set_checkbox($field = '', $value = '')\r
760         {\r
761                 if ($field == '' OR $value == '' OR  ! isset($_POST[$field]))\r
762                 {\r
763                         return '';\r
764                 }\r
765                         \r
766                 if ($_POST[$field] == $value)\r
767                 {\r
768                         return ' checked="checked"';\r
769                 }\r
770         }\r
771         \r
772         // --------------------------------------------------------------------\r
773         \r
774         /**\r
775          * Prep data for form\r
776          *\r
777          * This function allows HTML to be safely shown in a form.\r
778          * Special characters are converted.\r
779          *\r
780          * @access      public\r
781          * @param       string\r
782          * @return      string\r
783          */\r
784         function prep_for_form($data = '')\r
785         {\r
786                 if (is_array($data))\r
787                 {\r
788                         foreach ($data as $key => $val)\r
789                         {\r
790                                 $data[$key] = $this->prep_for_form($val);\r
791                         }\r
792                         \r
793                         return $data;\r
794                 }\r
795                 \r
796                 if ($this->_safe_form_data == FALSE OR $data == '')\r
797                 {\r
798                         return $data;\r
799                 }\r
800 \r
801                 return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));\r
802         }\r
803         \r
804         // --------------------------------------------------------------------\r
805         \r
806         /**\r
807          * Prep URL\r
808          *\r
809          * @access      public\r
810          * @param       string\r
811          * @return      string\r
812          */     \r
813         function prep_url($str = '')\r
814         {\r
815                 if ($str == 'http://' OR $str == '')\r
816                 {\r
817                         $_POST[$this->_current_field] = '';\r
818                         return;\r
819                 }\r
820                 \r
821                 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')\r
822                 {\r
823                         $str = 'http://'.$str;\r
824                 }\r
825                 \r
826                 $_POST[$this->_current_field] = $str;\r
827         }\r
828         \r
829         // --------------------------------------------------------------------\r
830         \r
831         /**\r
832          * Strip Image Tags\r
833          *\r
834          * @access      public\r
835          * @param       string\r
836          * @return      string\r
837          */     \r
838         function strip_image_tags($str)\r
839         {\r
840                 $_POST[$this->_current_field] = $this->CI->input->strip_image_tags($str);\r
841         }\r
842         \r
843         // --------------------------------------------------------------------\r
844         \r
845         /**\r
846          * XSS Clean\r
847          *\r
848          * @access      public\r
849          * @param       string\r
850          * @return      string\r
851          */     \r
852         function xss_clean($str)\r
853         {\r
854                 $_POST[$this->_current_field] = $this->CI->input->xss_clean($str);\r
855         }\r
856         \r
857         // --------------------------------------------------------------------\r
858         \r
859         /**\r
860          * Convert PHP tags to entities\r
861          *\r
862          * @access      public\r
863          * @param       string\r
864          * @return      string\r
865          */     \r
866         function encode_php_tags($str)\r
867         {\r
868                 $_POST[$this->_current_field] = str_replace(array('<?php', '<?PHP', '<?', '?>'),  array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);\r
869         }\r
870 \r
871 }\r
872 // END Validation Class\r
873 \r
874 /* End of file Validation.php */\r
875 /* Location: ./system/libraries/Validation.php */