From ecc7993a910bf8202ba022487288921a9c50e336 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 11:22:31 +0200 Subject: [ci skip] Update the Form_validation library docs --- .../source/libraries/form_validation.rst | 168 ++++++++------------- 1 file changed, 61 insertions(+), 107 deletions(-) (limited to 'user_guide_src/source/libraries') diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 5dffb1cd1..35f745fb7 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -340,10 +340,10 @@ commonly is:: set_value('field name') Open your myform.php view file and update the **value** in each field -using the ``set_value()`` function: +using the :func:`set_value()` function: -**Don't forget to include each field name in the ``set_value()`` -functions!** +**Don't forget to include each field name in the :func:`set_value()` +function calls!** :: @@ -380,11 +380,11 @@ Now reload your page and submit the form so that it triggers an error. Your form fields should now be re-populated .. note:: The :ref:`class-reference` section below - contains functions that permit you to re-populate menus, radio buttons, and checkboxes. -**Important Note:** If you use an array as the name of a form field, you -must supply it as an array to the function. Example:: +.. important:: If you use an array as the name of a form field, you + must supply it as an array to the function. Example:: @@ -559,7 +559,7 @@ Showing Errors Individually =========================== If you prefer to show an error message next to each form field, rather -than as a list, you can use the ``form_error()`` function. +than as a list, you can use the :func:`form_error()` function. Try it! Change your form so that it looks like this:: @@ -933,154 +933,108 @@ Name Parameter Description Class Reference *************** -.. class:: Form_validation - -The following methods are intended for use in your controller. +.. class:: CI_Form_validation -$this->form_validation->set_rules() -=================================== - - .. method:: set_rules ($field, $label = '', $rules = '') + .. method:: set_rules($field[, $label = ''[, $rules = '']]) :param string $field: The field name :param string $label: The field label :param mixed $rules: The rules, as a string with rules separated by a pipe "|", or an array or rules. - :rtype: Object + :returns: object Permits you to set validation rules, as described in the tutorial sections above: - - :ref:`setting-validation-rules` - - :ref:`saving-groups` + - :ref:`setting-validation-rules` + - :ref:`saving-groups` -$this->form_validation->run() -============================= - - .. method:: run ($group = '') + .. method:: run([$group = '']) :param string $group: The name of the validation group to run - :rtype: Boolean + :returns: bool Runs the validation routines. Returns boolean TRUE on success and FALSE on failure. You can optionally pass the name of the validation group via the method, as described in: :ref:`saving-groups` -$this->form_validation->set_message() -===================================== - - .. method:: set_message ($lang, $val = '') + .. method:: set_message($lang[, $val = '']) :param string $lang: The rule the message is for :param string $val: The message - :rtype: Object + :returns: object Permits you to set custom error messages. See :ref:`setting-error-messages` -$this->form_validation->set_data() -================================== + .. method:: set_error_delimiters([$prefix = '

'[, $suffix = '

']]) + + :param string $prefix: Error message prefix + :param string $suffix: Error message suffix + :returns: object + + Sets the default prefix and suffix for error messages. - .. method:: set_data ($data = '') + .. method:: set_data($data) :param array $data: The data to validate + :returns: void Permits you to set an array for validation, instead of using the default - $_POST array. + ``$_POST`` array. -$this->form_validation->reset_validation() -========================================== + .. method:: reset_validation() - .. method:: reset_validation () + :returns: void Permits you to reset the validation when you validate more than one array. This method should be called before validating each new array. -$this->form_validation->error_array() -===================================== + .. method:: error_array() - .. method:: error_array () - - :rtype: Array + :returns: array Returns the error messages as an array. -.. _helper-functions: - -**************** -Helper Reference -**************** - -The following helper functions are available for use in the view files -containing your forms. Note that these are procedural functions, so they -**do not** require you to prepend them with $this->form_validation. - -form_error() -============ - -Shows an individual error message associated with the field name -supplied to the function. Example:: + .. method:: error_string([$prefix = ''[, $suffix = '']]) - - -The error delimiters can be optionally specified. See the -:ref:`changing-delimiters` section above. - -validation_errors() -=================== - -Shows all error messages as a string: Example:: - - - -The error delimiters can be optionally specified. See the -:ref:`changing-delimiters` section above. - -set_value() -=========== + :param string $prefix: Error message prefix + :param string $suffix: Error message suffix + :returns: string -Permits you to set the value of an input form or textarea. You must -supply the field name via the first parameter of the function. The -second (optional) parameter allows you to set a default value for the -form. Example:: + Returns all error messages (as returned from error_array()) formatted as a + string and separated by a newline character. - + .. method:: error($field[, $prefix = ''[, $suffix = '']]) -The above form will show "0" when loaded for the first time. + :param string $field: Field name + :param string $prefix: Optional prefix + :param string $suffix: Optional suffix + :returns: string -set_select() -============ + Returns the error message for a specific field, optionally adding a + prefix and/or suffix to it (usually HTML tags). -If you use a - - - - + Checks to see if there is a rule set for the specified field. -set_checkbox() -============== - -Permits you to display a checkbox in the state it was submitted. The -first parameter must contain the name of the checkbox, the second -parameter must contain its value, and the third (optional) parameter -lets you set an item as the default (use boolean TRUE/FALSE). Example:: - - /> - /> +.. _helper-functions: -set_radio() -=========== +**************** +Helper Reference +**************** -Permits you to display radio buttons in the state they were submitted. -This function is identical to the **set_checkbox()** function above. +Please refer to the :doc:`Form Helper <../helpers/form_helper>` manual for +the following functions: -:: +- :func:`form_error()` +- :func:`validation_errors()` +- :func:`set_value()` +- :func:`set_select()` +- :func:`set_checkbox()` +- :func:`set_radio()` - /> - /> +Note that these are procedural functions, so they **do not** require you +to prepend them with ``$this->form_validation``. \ No newline at end of file -- cgit v1.2.3-24-g4f1b