From 0c06ba0c587b5ef97718bc3b19c6dba163b7acb0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Jun 2017 14:45:50 +0300 Subject: Implement #2436 (access to FV processed data) --- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/libraries/form_validation.rst | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index c1f53dac0..db2be2014 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -52,6 +52,7 @@ Release Date: Not Released - Changed method ``set_rules()`` to throw a ``BadMethodCallException`` when its first parameter is not an array and the ``$rules`` one is unused. - Added rule **valid_mac**, which replicates PHP's native ``filter_var()`` with ``FILTER_VALIDATE_MAC``. - Added ability to validate entire arrays at once, if ``is_array`` is within the list of rules. + - Added ability to fetch processed data via a second parameter to ``run()``. - :doc:`HTML Table Library ` changes include: diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 6a92cc983..fd2f3af94 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -881,6 +881,24 @@ When a rule group is named identically to a controller class/method it will be used automatically when the ``run()`` method is invoked from that class/method. +Accessing validated/processed data +================================== + +By default, validation will be performed directly on the ``$_POST`` array, +and any possible modifications (like trimming whitespace, for example) +would be written back onto it. +However, if you want to keep the original input data intact, or have used +``set_data()`` to pass a custom set of inputs, you would likely want to +fetch the now-modified data. In order to do that, you can pass a variable +as the second parameter to ``run()``:: + + $input = array('name' => ' White Space '); + $output = NULL; + + $this->form_validation->set_rules('name', 'Name', 'required|trim'); + $this->form_validation->run(NULL, $output); + // $output will now contain: array('name' => 'White Space'); + .. _using-arrays-as-field-names: *************************** @@ -1043,9 +1061,10 @@ Class Reference - :ref:`setting-validation-rules` - :ref:`saving-groups` - .. php:method:: run([$group = '']) + .. php:method:: run([$config = NULL[, $data = NULL]]) :param string $group: The name of the validation group to run + :param mixed $data: Optional variable to assign validated data to :returns: TRUE on success, FALSE if validation failed :rtype: bool -- cgit v1.2.3-24-g4f1b