You are here

README.txt in Webform Validation 6

$Id

Description
-----------
This module adds an extra tab to each webform node, allowing you to specify validation rules for your webform components.
You can create one or more of the predefined validation rules, and select which webform component(s) should be validated against those.
By using the hooks provided by this module, you can also define your own validation rules in your own modules.

The following validation rules are currently included:
- Numeric values (optionally specify min and / or max value)
- Minimum length
- Maximum length
- Minimum number of words
- Maximum number of words
- Equal values on multiple fields
- Unique values on multiple fields
- Specific value
- Require at least one of two fields
- Require at least one of several fields
- Minimum number of selections required
- Maximum number of selections allowed
- Exact number of selections required
- Plain text (disallow tags)
- Regular expression
- Must be empty (Anti-Spam: Hide with CSS)
- Words blacklist
- Must match a username

Installation
------------
1) Place the module folder in your sites/all/modules folder
2) Make sure you have the webform module enabled
3) Activate the module via admin/build/modules

Usage
-----
Once you have installed the module, an extra tab will appear on the node's webform management pages (tab "Edit" in Webform 2.x, tab "Webform" in Webform 3.x).
This extra tab is labeled "Webform validation".
Upon selecting this tab, you can choose to add one of the available validation rules to your webform.
Make sure you have added the webform components you wish to validate before adding the validation rule.

After clicking the link to add the desired validation rule, you can specify the following details for your rule:
- an administrative name to describe the validation rule
- one or more webform components that should be validated against this rule
(depending on the chosen rule, you will have to select a specific number of components for the validation rule to work properly).

Depending on the chosen rule, more form fields will be available on the rules form:
- optionally an extra setting to further configure the rule
- optionally a custom error message textfield

Once you have configured your desired validation rules for the selected webform components, every time a user fills in the webform,
the validation will be triggered for the selected components, and show the user a standard form error message when entered data doesn't pass the validation rule you have set up.

Adding custom validation rules
-------------------------------
The following steps will let you add custom validators through your module:

1/ Implement hook hook_webform_validation_validators().
   This hook implementation should return an array of validator key => options array entries.
   The options array can contain the following configuration keys:
   * name (required): name of the validator
   * component types (required): defines which component types can be validated by this validator. Specify 'all' to allow all types
   * custom_error (optional): define whether a user can specify a custom error message upon creating the validation rule.
   * custom_data (optional): define whether custom data can be added to the validation rule
   * min_components (optional): define the minimum number of components to be selected for creating a validation rule
   * max_components (optional): define the maximum number of components to be selected for creating a validation rule
   * description (optional): provide a descriptive explanation about the validator

   See function webform_validation_webform_validation_validators() in webform_validation.validators.inc for a live example

 2/ Implement hook hook_webform_validation_validate($validator_name, $items, $components, $rule).
    This hook gets passed 4 parameters, which will allow you to react to your custom validator (or any other validator for that matter).
    Explanation about these parameters:
    * $validator_name: this is the validator name (i.e. array key as entered in hook_webform_validation_validators)
    * $items: array containing user submitted entries to be validated.
    * $components: this array contains the definitions of the webform components in your form
    * $rule: this array contains the details of your validation rule

    See function webform_validation_webform_validation_validate() in webform_validation.validators.inc for a live example

Additional hooks
-----------------
The hook hook_webform_validation($type, $op, $data) can be used to react on various webform_validation based actions.
* $type - possible values: 'rule'
* $op - possible values: 'add', 'edit', 'delete'
* $data - array with rule data in case of $op add/edit, rule id in case of $op delete.

The hook hook_webform_validator_alter(&$validators) can be used to alter the array of validators that is being generated by hook_webform_validation_validators().
* $validators - array of validators as supplied by modules implementing hook_webform_validation_validators().

Author
------
Sven Decabooter (http://drupal.org/user/35369)
The author can be contacted for paid customizations of this module as well as Drupal consulting and development.

File

README.txt
View source
  1. $Id
  2. Description
  3. -----------
  4. This module adds an extra tab to each webform node, allowing you to specify validation rules for your webform components.
  5. You can create one or more of the predefined validation rules, and select which webform component(s) should be validated against those.
  6. By using the hooks provided by this module, you can also define your own validation rules in your own modules.
  7. The following validation rules are currently included:
  8. - Numeric values (optionally specify min and / or max value)
  9. - Minimum length
  10. - Maximum length
  11. - Minimum number of words
  12. - Maximum number of words
  13. - Equal values on multiple fields
  14. - Unique values on multiple fields
  15. - Specific value
  16. - Require at least one of two fields
  17. - Require at least one of several fields
  18. - Minimum number of selections required
  19. - Maximum number of selections allowed
  20. - Exact number of selections required
  21. - Plain text (disallow tags)
  22. - Regular expression
  23. - Must be empty (Anti-Spam: Hide with CSS)
  24. - Words blacklist
  25. - Must match a username
  26. Installation
  27. ------------
  28. 1) Place the module folder in your sites/all/modules folder
  29. 2) Make sure you have the webform module enabled
  30. 3) Activate the module via admin/build/modules
  31. Usage
  32. -----
  33. Once you have installed the module, an extra tab will appear on the node's webform management pages (tab "Edit" in Webform 2.x, tab "Webform" in Webform 3.x).
  34. This extra tab is labeled "Webform validation".
  35. Upon selecting this tab, you can choose to add one of the available validation rules to your webform.
  36. Make sure you have added the webform components you wish to validate before adding the validation rule.
  37. After clicking the link to add the desired validation rule, you can specify the following details for your rule:
  38. - an administrative name to describe the validation rule
  39. - one or more webform components that should be validated against this rule
  40. (depending on the chosen rule, you will have to select a specific number of components for the validation rule to work properly).
  41. Depending on the chosen rule, more form fields will be available on the rules form:
  42. - optionally an extra setting to further configure the rule
  43. - optionally a custom error message textfield
  44. Once you have configured your desired validation rules for the selected webform components, every time a user fills in the webform,
  45. the validation will be triggered for the selected components, and show the user a standard form error message when entered data doesn't pass the validation rule you have set up.
  46. Adding custom validation rules
  47. -------------------------------
  48. The following steps will let you add custom validators through your module:
  49. 1/ Implement hook hook_webform_validation_validators().
  50. This hook implementation should return an array of validator key => options array entries.
  51. The options array can contain the following configuration keys:
  52. * name (required): name of the validator
  53. * component types (required): defines which component types can be validated by this validator. Specify 'all' to allow all types
  54. * custom_error (optional): define whether a user can specify a custom error message upon creating the validation rule.
  55. * custom_data (optional): define whether custom data can be added to the validation rule
  56. * min_components (optional): define the minimum number of components to be selected for creating a validation rule
  57. * max_components (optional): define the maximum number of components to be selected for creating a validation rule
  58. * description (optional): provide a descriptive explanation about the validator
  59. See function webform_validation_webform_validation_validators() in webform_validation.validators.inc for a live example
  60. 2/ Implement hook hook_webform_validation_validate($validator_name, $items, $components, $rule).
  61. This hook gets passed 4 parameters, which will allow you to react to your custom validator (or any other validator for that matter).
  62. Explanation about these parameters:
  63. * $validator_name: this is the validator name (i.e. array key as entered in hook_webform_validation_validators)
  64. * $items: array containing user submitted entries to be validated.
  65. * $components: this array contains the definitions of the webform components in your form
  66. * $rule: this array contains the details of your validation rule
  67. See function webform_validation_webform_validation_validate() in webform_validation.validators.inc for a live example
  68. Additional hooks
  69. -----------------
  70. The hook hook_webform_validation($type, $op, $data) can be used to react on various webform_validation based actions.
  71. * $type - possible values: 'rule'
  72. * $op - possible values: 'add', 'edit', 'delete'
  73. * $data - array with rule data in case of $op add/edit, rule id in case of $op delete.
  74. The hook hook_webform_validator_alter(&$validators) can be used to alter the array of validators that is being generated by hook_webform_validation_validators().
  75. * $validators - array of validators as supplied by modules implementing hook_webform_validation_validators().
  76. Author
  77. ------
  78. Sven Decabooter (http://drupal.org/user/35369)
  79. The author can be contacted for paid customizations of this module as well as Drupal consulting and development.