Changeset 1441 for trunk/modules/forge/libraries/Form_Input.php
- Timestamp:
- 12/07/2007 12:02:27 PM (13 months ago)
- Files:
-
- 1 modified
-
trunk/modules/forge/libraries/Form_Input.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/forge/libraries/Form_Input.php
r1439 r1441 42 42 if ($method == 'rules') 43 43 { 44 $this->add_rules(explode('|', $args[0])); 44 // Set rules and action 45 $rules = $args[0]; 46 $action = substr($rules, 0, 1); 47 48 if (in_array($action, array('-', '+', '='))) 49 { 50 // Remove the action from the rules 51 $rules = substr($rules, 1); 52 } 53 else 54 { 55 // Default action is replace 56 $action = '='; 57 } 58 59 $this->add_rules(explode('|', $rules), $action); 45 60 } 46 61 elseif ($method == 'name') … … 106 121 } 107 122 108 protected function add_rules( array $rules) 109 { 123 protected function add_rules( array $rules, $action = '=') 124 { 125 if ($action === '=') 126 { 127 // Just replace the rules 128 $this->rules = $rules; 129 return; 130 } 131 110 132 foreach($rules as $rule) 111 133 { 112 if ( ! in_array($rule, $this->rules)) 113 { 114 $this->rules[] = $rule; 134 if ($action === '-') 135 { 136 if ($key = array_search($rule, $this->rules)) 137 { 138 // Remove the rule 139 unset($this->rules[$key]); 140 } 141 } 142 else 143 { 144 if ( ! in_array($rule, $this->rules)) 145 { 146 if ($action == '+') 147 { 148 array_unshift($this->rules, $rule); 149 } 150 else 151 { 152 $this->rules[] = $rule; 153 } 154 } 115 155 } 116 156 } … … 245 285 protected function rule_length($min, $max = NULL) 246 286 { 247 // Get the length 248 $length = strlen($this->value); 287 // Get the length, return if zero 288 if (($length = strlen($this->value)) === 0) 289 return; 249 290 250 291 if ($max == NULL)
