README.txt 5.1 KB

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