From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- user_guide/libraries/validation.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'user_guide/libraries/validation.html') diff --git a/user_guide/libraries/validation.html b/user_guide/libraries/validation.html index 0a4905a71..aaf416dac 100644 --- a/user_guide/libraries/validation.html +++ b/user_guide/libraries/validation.html @@ -12,7 +12,7 @@ @@ -75,8 +75,8 @@ Form Validation
  1. Check for required data.
  2. -
  3. Verify that the data is of the correct type, and meets the correct criteria. (For example, if a username is submitted -it must be validated to contain only permitted characters. It must be of a minimum length, +
  4. Verify that the data is of the correct type, and meets the correct criteria. (For example, if a username is submitted +it must be validated to contain only permitted characters. It must be of a minimum length, and not exceed a maximum length. The username can't be someone else's existing username, or perhaps even a reserved word. Etc.)
  5. Sanitize the data for security.
  6. Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)
  7. @@ -195,7 +195,7 @@ class Form extends Controller { www.your-site.com/index.php/form/ -

    If you submit the form you should simply see the form reload. That's because you haven't set up any validation +

    If you submit the form you should simply see the form reload. That's because you haven't set up any validation rules yet, which we'll get to in a moment.

    @@ -219,8 +219,8 @@ and flexible in the event your URLs change.

The controller (form.php) has one function: index(). This function initializes the validation class and -loads the form helper and URL helper used by your view files. It also runs -the validation routine. Based on +loads the form helper and URL helper used by your view files. It also runs +the validation routine. Based on whether the validation was successful it either presents the form or the success page.

Since you haven't told the validation class to validate anything yet, it returns "false" (boolean false) by default. The run() @@ -313,7 +313,7 @@ $rules['email'] = "required|valid_email";

Prepping Data

-

In addition to the validation functions like the ones we used above, you can also prep your data in various ways. +

In addition to the validation functions like the ones we used above, you can also prep your data in various ways. For example, you can set up rules like this: $rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
@@ -391,17 +391,17 @@ callback function for you to process.

To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix.

-

The error message was set using the $this->validation->set_message function. +

The error message was set using the $this->validation->set_message function. Just remember that the message key (the first parameter) must match your function name.

-

Note: You can apply your own custom error messages to any rule, just by setting the +

Note: You can apply your own custom error messages to any rule, just by setting the message similarly. For example, to change the message for the "required" rule you will do this:

$this->validation->set_message('required', 'Your custom message here');

Re-populating the form

-

Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. +

Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. This is done similarly to your rules. Add the following code to your controller, just below your rules:

$fields['username'] = 'Username';
@@ -411,7 +411,7 @@ $fields['email'] = 'Email Address';

$this->validation->set_fields($fields);
-

The array keys are the actual names of the form fields, the value represents the full name that you want shown in the +

The array keys are the actual names of the form fields, the value represents the full name that you want shown in the error message.

The index function of your controller should now look like this:

@@ -512,7 +512,7 @@ and the error messages will contain a more relevant field name.

have set (<p> tags by default).

Note: To display errors this way you must remember to set your fields using the $this->validation->set_fields -function described earlier. The errors will be turned into variables that have "_error" after your field name. +function described earlier. The errors will be turned into variables that have "_error" after your field name. For example, your "username" error will be available at:
$this->validation->username_error.

@@ -666,7 +666,7 @@ like trim, htmlspecialchars, urldecode, etc.

Dealing with Select Menus, Radio Buttons, and Checkboxes -

If you use select menus, radio buttons or checkboxes, you will want the state of +

If you use select menus, radio buttons or checkboxes, you will want the state of these items to be retained in the event of an error. The Validation class has three functions that help you do this:

set_select()

-- cgit v1.2.3-24-g4f1b