Show
Ignore:
Timestamp:
06/20/2008 10:19:28 AM (5 months ago)
Author:
Shadowhand
Message:

Changed Validation::safe_array() to allow passing a set of keys to use, instead of *all* fields

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Validation.php

    r2670 r2869  
    9292        /** 
    9393         * Returns the ArrayObject values, removing all inputs without rules. 
     94         * To choose specific inputs, list the field name as arguments. 
    9495         * 
    9596         * @return  array 
     
    106107                )); 
    107108 
     109                // Load choices 
     110                $choices = func_get_args(); 
     111                $choices = empty($choices) ? NULL : array_combine($choices, $choices); 
     112 
    108113                $safe = array(); 
    109114                foreach ($all_fields as $i => $field) 
     
    118123                        } 
    119124 
    120                         // Make sure all fields are defined 
    121                         $safe[$field] = isset($this[$field]) ? $this[$field] : NULL; 
     125                        if ($choices === NULL OR isset($choices[$field])) 
     126                        { 
     127                                // Make sure all fields are defined 
     128                                $safe[$field] = isset($this[$field]) ? $this[$field] : NULL; 
     129                        } 
    122130                } 
    123131