summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/form_helper.php33
-rw-r--r--system/libraries/Form_validation.php15
-rw-r--r--user_guide_src/source/changelog.rst4
3 files changed, 46 insertions, 6 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index d6e3e85fa..200da8ac5 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -642,14 +642,37 @@ if ( ! function_exists('set_value'))
*/
function set_value($field = '', $default = '', $is_textarea = FALSE)
{
- if (FALSE === ($OBJ =& _get_validation_object()))
+ if (FALSE !== ($OBJ =& _get_validation_object()) && $OBJ->has_rule($field))
{
- return isset($_POST[$field])
- ? form_prep($_POST[$field], $is_textarea)
- : form_prep($default, $is_textarea);
+ return form_prep($OBJ->set_value($field, $default), $is_textarea);
+ }
+
+ // We couldn't find the $field in validator, so try in $_POST array
+ $index = $field;
+ $container = $_POST;
+
+ // Test if the $field is an array name, and try to obtain the final index
+ if (preg_match_all('/\[(.*?)\]/', $field, $matches))
+ {
+ sscanf($field, '%[^[][', $index);
+ for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
+ {
+ if (isset($container[$index]) && $matches[1][$i] !== '')
+ {
+ $container = $container[$index];
+ $index = $matches[1][$i];
+ }
+ else
+ {
+ $container = array();
+ break;
+ }
+ }
}
- return form_prep($OBJ->set_value($field, $default), $is_textarea);
+ return isset($container[$index])
+ ? form_prep($container[$index], $is_textarea)
+ : form_prep($default, $is_textarea);
}
}
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 172e799f6..1ed50844c 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -836,6 +836,21 @@ class CI_Form_validation {
// --------------------------------------------------------------------
/**
+ * Checks if the rule is present within the validator
+ *
+ * Permits you to check if a rule is present within the validator
+ *
+ * @param string the field name
+ * @return bool
+ */
+ public function has_rule($field)
+ {
+ return isset($this->_field_data[$field]);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get the value from a form
*
* Permits you to repopulate a form field with the value it was submitted
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index a5f560564..2c2da6aaa 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -244,6 +244,7 @@ Release Date: Not Released
- Added support for named parameters in error messages.
- :doc:`Language <libraries/language>` line keys must now be prefixed with **form_validation_**.
- Added rule **alpha_numeric_spaces**.
+ - Added method ``has_rule()`` to determine if a rule exists.
- Added support for setting :doc:`Table <libraries/table>` class defaults in a config file.
- :doc:`Caching Library <libraries/caching>` changes include:
- Added Wincache driver.
@@ -463,7 +464,7 @@ Bug fixes for 3.0
- Fixed a bug (#1255) - :doc:`User Agent Library <libraries/user_agent>` method ``is_referral()`` only checked if ``$_SERVER['HTTP_REFERER']`` exists.
- Fixed a bug (#1146) - :doc:`Download Helper <helpers/download_helper>` function ``force_download()`` incorrectly sent *Cache-Control* directives *pre-check* and *post-check* to Internet Explorer.
- Fixed a bug (#1811) - :doc:`URI Library <libraries/uri>` didn't properly cache segments for ``uri_to_assoc()`` and ``ruri_to_assoc()``.
-- Fixed a bug (#1506) - :doc:`Form Helpers <helpers/form_helper>` set empty *name* attributes.
+- Fixed a bug (#1506) - :doc:`Form Helper <helpers/form_helper>` set empty *name* attributes.
- Fixed a bug (#59) - :doc:`Query Builder <database/query_builder>` method ``count_all_results()`` ignored the DISTINCT clause.
- Fixed a bug (#1624) - :doc:`Form Validation Library <libraries/form_validation>` rule **matches** didn't property handle array field names.
- Fixed a bug (#1630) - :doc:`Form Helper <helpers/form_helper>` function ``set_value()`` didn't escape HTML entities.
@@ -488,6 +489,7 @@ Bug fixes for 3.0
- Fixed a bug (#2211) - :doc:`Migration Library <libraries/migration>` extensions couldn't execute ``CI_Migration::__construct()``.
- Fixed a bug (#2255) where ``smtp_timeout`` was not being applied to read and writes for the socket.
- Fixed a bug (#2239) of missing subject when using ``bcc_batch_mode``.
+- Fixed a bug (#2236) - :doc:`Form Helper <helpers/form_helper>` incorrectly determined the value to return in method ``set_value()``.
Version 2.1.3
=============