summaryrefslogtreecommitdiffstats
path: root/system/libraries/Form_validation.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Form_validation.php')
-rw-r--r--system/libraries/Form_validation.php96
1 files changed, 65 insertions, 31 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index b3efe82cf..4ad31ebfa 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -2,7 +2,7 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
*
* NOTICE OF LICENSE
*
@@ -48,10 +48,7 @@ class CI_Form_validation {
protected $error_string = '';
protected $_safe_form_data = FALSE;
protected $validation_data = array();
-
- /**
- * Constructor
- */
+
public function __construct($rules = array())
{
$this->CI =& get_instance();
@@ -68,7 +65,7 @@ class CI_Form_validation {
mb_internal_encoding($this->CI->config->item('charset'));
}
- log_message('debug', "Form Validation Class Initialized");
+ log_message('debug', 'Form Validation Class Initialized');
}
// --------------------------------------------------------------------
@@ -85,9 +82,9 @@ class CI_Form_validation {
*/
public function set_rules($field, $label = '', $rules = '')
{
- // No reason to set rules if we have no POST data
+ // No reason to set rules if we have no POST data
// or a validation array has not been specified
- if (count($_POST) === 0 && count($this->validation_data) === 0)
+ if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
{
return $this;
}
@@ -162,23 +159,28 @@ class CI_Form_validation {
}
// --------------------------------------------------------------------
-
+
/**
* By default, form validation uses the $_POST array to validate
- *
+ *
* If an array is set through this method, then this array will
* be used instead of the $_POST array
- *
- * @param array $data
+ *
+ * Note that if you are validating multiple arrays, then the
+ * reset_validation() function should be called after validating
+ * each array due to the limitations of CI's singleton
+ *
+ * @param array $data
+ * @return void
*/
public function set_data($data = '')
{
if ( ! empty($data) && is_array($data))
{
- $this->validation_data = $data;
+ $this->validation_data = $data;
}
}
-
+
// --------------------------------------------------------------------
/**
@@ -325,9 +327,6 @@ class CI_Form_validation {
{
return FALSE;
}
-
- // Clear any previous validation data
- $this->_reset_validation();
// Does the _field_data array containing the validation rules exist?
// If not, we look to see if they were assigned via a config file
@@ -891,7 +890,7 @@ class CI_Form_validation {
*/
public function matches($str, $field)
{
- $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
+ $validation_array = ( ! empty($this->validation_data)) ? $this->validation_data : $_POST;
if ( ! isset($validation_array[$field]))
{
return FALSE;
@@ -1142,7 +1141,7 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
- * Greather than
+ * Greater than
*
* @param string
* @return bool
@@ -1159,6 +1158,23 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Equal to or Greater than
+ *
+ * @param string
+ * @return bool
+ */
+ public function greater_than_equal_to($str, $min)
+ {
+ if ( ! is_numeric($str))
+ {
+ return FALSE;
+ }
+ return $str >= $min;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Less than
*
* @param string
@@ -1176,6 +1192,23 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Equal to or Less than
+ *
+ * @param string
+ * @return bool
+ */
+ public function less_than_equal_to($str, $max)
+ {
+ if ( ! is_numeric($str))
+ {
+ return FALSE;
+ }
+ return $str <= $max;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Is a Natural number (0,1,2,3, etc.)
*
* @param string
@@ -1307,25 +1340,26 @@ class CI_Form_validation {
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
}
-
+
// --------------------------------------------------------------------
-
- /**
- * Reset validation vars
- *
- * Prevents subsequent validation routines from being affected by the
+
+ /**
+ * Reset validation vars
+ *
+ * Prevents subsequent validation routines from being affected by the
* results of any previous validation routine due to the CI singleton.
- *
- * @return void
- */
- protected function _reset_validation()
- {
+ *
+ * @return void
+ */
+ public function reset_validation()
+ {
$this->_field_data = array();
$this->_config_rules = array();
$this->_error_array = array();
$this->_error_messages = array();
$this->error_string = '';
- }
+ }
+
}
/* End of file Form_validation.php */