From 53b70e19ae8685a95a5d6b7651746279d350407e Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 20 Sep 2008 04:48:14 +0000 Subject: Added the ability to use callbacks even when a field has no data --- system/libraries/Form_validation.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'system/libraries/Form_validation.php') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index fe7502773..6ef11e345 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -479,19 +479,29 @@ class CI_Form_validation { return; } - + // -------------------------------------------------------------------- // If the field is blank, but NOT required, no further tests are necessary - if ( ! in_array('required', $rules, TRUE) AND is_null($postdata)) + $callback = FALSE; + if ( ! in_array('required', $rules) AND is_null($postdata)) { - return; + // Before we bail out, does the rule contain a callback? + if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match)) + { + $callback = TRUE; + $rules = (array('1' => $match[1])); + } + else + { + return; + } } // -------------------------------------------------------------------- // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata)) + if (is_null($postdata) AND $callback == FALSE) { if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) { -- cgit v1.2.3-24-g4f1b