summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/libraries/form_validation.rst
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-02-09 16:30:06 +0100
committerAndrey Andreev <narf@devilix.net>2014-02-09 16:30:06 +0100
commitc2804a3f3eb085abcc50e8df51085db7a94c18d2 (patch)
treeb53e8a2798a75fa4f92ee2cc3201635ce7df319a /user_guide_src/source/libraries/form_validation.rst
parentf6600f840125eadf2366c2244f78ad95defb156b (diff)
parentdb97fe561f03284a287c9a588ac1ff19a9f5e71d (diff)
Merge branch 'develop' into 'feature/encryption'
Diffstat (limited to 'user_guide_src/source/libraries/form_validation.rst')
-rw-r--r--user_guide_src/source/libraries/form_validation.rst229
1 files changed, 96 insertions, 133 deletions
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 1076b1433..988d6fa25 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -353,10 +353,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!**
::
@@ -393,11 +393,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 <select> menus,
+ contains methods that permit you to re-populate <select> 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::
<input type="text" name="colors[]" value="<?php echo set_value('colors[]'); ?>" size="50" />
@@ -497,8 +497,8 @@ some particular rule, use the set_rules() method::
Where rule corresponds to the name of a particular rule, and Error
Message is the text you would like displayed.
-If you'd like to include a field's "human" name, or the optional
-parameter some rules allow for (such as max_length), you can add the
+If you'd like to include a field's "human" name, or the optional
+parameter some rules allow for (such as max_length), you can add the
**{field}** and **{param}** tags to your message, respectively::
$this->form_validation->set_message('min_length', '{field} must have at least {param} characters.');
@@ -579,7 +579,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::
@@ -880,15 +880,15 @@ use:
========================= ========== ============================================================================================= =======================
Rule Parameter Description Example
========================= ========== ============================================================================================= =======================
-**required** No Returns FALSE if the form element is empty.
-**matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
-**differs** Yes Returns FALSE if the form element does not differ from the one in the parameter. differs[form_item]
-**is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field]
- parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be
+**required** No Returns FALSE if the form element is empty.
+**matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
+**differs** Yes Returns FALSE if the form element does not differ from the one in the parameter. differs[form_item]
+**is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field]
+ parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be
enabled in order to work.
-**min_length** Yes Returns FALSE if the form element is shorter then the parameter value. min_length[3]
-**max_length** Yes Returns FALSE if the form element is longer then the parameter value. max_length[12]
-**exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8]
+**min_length** Yes Returns FALSE if the form element is shorter than the parameter value. min_length[3]
+**max_length** Yes Returns FALSE if the form element is longer than the parameter value. max_length[12]
+**exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8]
**greater_than** Yes Returns FALSE if the form element is less than or equal to the parameter value or not greater_than[8]
numeric.
**greater_than_equal_to** Yes Returns FALSE if the form element is less than the parameter value, greater_than_equal_to[8]
@@ -897,15 +897,15 @@ Rule Parameter Description
not numeric.
**less_than_equal_to** Yes Returns FALSE if the form element is greater than the parameter value, less_than_equal_to[8]
or not numeric.
-**alpha** No Returns FALSE if the form element contains anything other than alphabetical characters.
+**alpha** No Returns FALSE if the form element contains anything other than alphabetical characters.
**alpha_numeric** No Returns FALSE if the form element contains anything other than alpha-numeric characters.
**alpha_numeric_spaces** No Returns FALSE if the form element contains anything other than alpha-numeric characters
- or spaces. Should be used after trim to avoid spaces at the beginning or end.
-**alpha_dash** No Returns FALSE if the form element contains anything other than alpha-numeric characters,
- underscores or dashes.
-**numeric** No Returns FALSE if the form element contains anything other than numeric characters.
-**integer** No Returns FALSE if the form element contains anything other than an integer.
-**decimal** No Returns FALSE if the form element contains anything other than a decimal number.
+ or spaces. Should be used after trim to avoid spaces at the beginning or end.
+**alpha_dash** No Returns FALSE if the form element contains anything other than alpha-numeric characters,
+ underscores or dashes.
+**numeric** No Returns FALSE if the form element contains anything other than numeric characters.
+**integer** No Returns FALSE if the form element contains anything other than an integer.
+**decimal** No Returns FALSE if the form element contains anything other than a decimal number.
**is_natural** No Returns FALSE if the form element contains anything other than a natural number:
0, 1, 2, 3, etc.
**is_natural_no_zero** No Returns FALSE if the form element contains anything other than a natural
@@ -954,155 +954,118 @@ Name Parameter Description
Class Reference
***************
-.. php: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 = '']])
- .. php:method:: set_rules ($field, $label = '', $rules = '', $errors = array())
-
- :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.
- :param array $errors: Custom error messages
- :rtype: Object
+ :param string $field: Field name
+ :param string $label: Field label
+ :param mixed $rules: Validation rules, as a string list separated by a pipe "|", or as an array or rules
+ :returns: CI_Form_validation instance (method chaining)
+ :rtype: CI_Form_validation
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()
-=============================
-
- .. php:method:: run ($group = '')
+ .. method:: run([$group = ''])
- :param string $group: The name of the validation group to run
- :rtype: Boolean
+ :param string $group: The name of the validation group to run
+ :returns: TRUE on success, FALSE if validation failed
+ :rtype: 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()
-=====================================
-
- .. php: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
+ :param string $lang: The rule the message is for
+ :param string $val: The message
+ :returns: CI_Form_validation instance (method chaining)
+ :rtype: CI_Form_validation
Permits you to set custom error messages. See :ref:`setting-error-messages`
-$this->form_validation->set_data()
-==================================
-
- .. php:method:: set_data ($data = '')
+ .. method:: set_error_delimiters([$prefix = '<p>'[, $suffix = '</p>']])
- :param array $data: The data to validate
+ :param string $prefix: Error message prefix
+ :param string $suffix: Error message suffix
+ :returns: CI_Form_validation instance (method chaining)
+ :rtype: CI_Form_validation
+
+ Sets the default prefix and suffix for error messages.
+
+ .. method:: set_data($data)
+
+ :param array $data: Array of data validate
+ :returns: CI_Form_validation instance (method chaining)
+ :rtype: CI_Form_validation
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()
- .. php:method:: reset_validation ()
+ :returns: CI_Form_validation instance (method chaining)
+ :rtype: CI_Form_validation
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()
-=====================================
-
- .. php:method:: error_array ()
+ .. method:: error_array()
- :rtype: Array
+ :returns: Array of error messages
+ :rtype: 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::
-
- <?php echo form_error('username'); ?>
-
-The error delimiters can be optionally specified. See the
-:ref:`changing-delimiters` section above.
+ .. method:: error_string([$prefix = ''[, $suffix = '']])
-validation_errors()
-===================
+ :param string $prefix: Error message prefix
+ :param string $suffix: Error message suffix
+ :returns: Error messages as a string
+ :rtype: string
-Shows all error messages as a string: Example::
+ Returns all error messages (as returned from error_array()) formatted as a
+ string and separated by a newline character.
- <?php echo validation_errors(); ?>
+ .. method:: error($field[, $prefix = ''[, $suffix = '']])
-The error delimiters can be optionally specified. See the
-:ref:`changing-delimiters` section above.
-
-set_value()
-===========
+ :param string $field: Field name
+ :param string $prefix: Optional prefix
+ :param string $suffix: Optional suffix
+ :returns: Error message string
+ :rtype: 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 the error message for a specific field, optionally adding a
+ prefix and/or suffix to it (usually HTML tags).
- <input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" />
+ .. method:: has_rule($field)
-The above form will show "0" when loaded for the first time.
+ :param string $field: Field name
+ :returns: TRUE if the field has rules set, FALSE if not
+ :rtype: bool
-set_select()
-============
+ Checks to see if there is a rule set for the specified field.
-If you use a <select> menu, this function permits you to display the
-menu item that was selected. The first parameter must contain the name
-of the select menu, the second parameter must contain the value of each
-item, and the third (optional) parameter lets you set an item as the
-default (use boolean TRUE/FALSE).
-
-Example::
-
- <select name="myselect">
- <option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
- <option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
- <option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
- </select>
-
-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::
-
- <input type="checkbox" name="mycheck[]" value="1" <?php echo set_checkbox('mycheck[]', '1'); ?> />
- <input type="checkbox" name="mycheck[]" value="2" <?php echo set_checkbox('mycheck[]', '2'); ?> />
+.. _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()`
- <input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
- <input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />
+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