@@ 243-263 (lines=21) @@ | ||
240 | * @param string fields to apply filter to, use TRUE for all fields |
|
241 | * @return Validation_Core |
|
242 | */ |
|
243 | public function pre_filter($filter, $field = true) |
|
244 | { |
|
245 | if ($field === true or $field === '*') { |
|
246 | // Use wildcard |
|
247 | $fields = array('*'); |
|
248 | } else { |
|
249 | // Add the filter to specific inputs |
|
250 | $fields = func_get_args(); |
|
251 | $fields = array_slice($fields, 1); |
|
252 | } |
|
253 | ||
254 | // Convert to a proper callback |
|
255 | $filter = $this->callback($filter); |
|
256 | ||
257 | foreach ($fields as $field) { |
|
258 | // Add the filter to specified field |
|
259 | $this->pre_filters[$field][] = $filter; |
|
260 | } |
|
261 | ||
262 | return $this; |
|
263 | } |
|
264 | ||
265 | /** |
|
266 | * Add a post-filter to one or more inputs. Post-filters are applied after |
|
@@ 274-294 (lines=21) @@ | ||
271 | * @param string fields to apply filter to, use TRUE for all fields |
|
272 | * @return Validation_Core |
|
273 | */ |
|
274 | public function post_filter($filter, $field = true) |
|
275 | { |
|
276 | if ($field === true) { |
|
277 | // Use wildcard |
|
278 | $fields = array('*'); |
|
279 | } else { |
|
280 | // Add the filter to specific inputs |
|
281 | $fields = func_get_args(); |
|
282 | $fields = array_slice($fields, 1); |
|
283 | } |
|
284 | ||
285 | // Convert to a proper callback |
|
286 | $filter = $this->callback($filter); |
|
287 | ||
288 | foreach ($fields as $field) { |
|
289 | // Add the filter to specified field |
|
290 | $this->post_filters[$field][] = $filter; |
|
291 | } |
|
292 | ||
293 | return $this; |
|
294 | } |
|
295 | ||
296 | /** |
|
297 | * Add rules to a field. Validation rules may only return TRUE or FALSE and |
|
@@ 355-375 (lines=21) @@ | ||
352 | * @param callbacks callbacks (unlimited number) |
|
353 | * @return Validation_Core |
|
354 | */ |
|
355 | public function add_callbacks($field, $callbacks) |
|
356 | { |
|
357 | // Get all callbacks as an array |
|
358 | $callbacks = func_get_args(); |
|
359 | $callbacks = array_slice($callbacks, 1); |
|
360 | ||
361 | if ($field === true) { |
|
362 | // Use wildcard |
|
363 | $field = '*'; |
|
364 | } |
|
365 | ||
366 | foreach ($callbacks as $callback) { |
|
367 | // Convert to a proper callback |
|
368 | $callback = $this->callback($callback); |
|
369 | ||
370 | // Add the callback to specified field |
|
371 | $this->callbacks[$field][] = $callback; |
|
372 | } |
|
373 | ||
374 | return $this; |
|
375 | } |
|
376 | ||
377 | /** |
|
378 | * Validate by processing pre-filters, rules, callbacks, and post-filters. |