Project

General

Profile

Paste
Download (5.09 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / webform_validation / README.txt @ 1f623f01

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

    
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

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

    
33
Usage
34
-----
35
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).
36
This extra tab is labeled "Webform validation".
37
Upon selecting this tab, you can choose to add one of the available validation rules to your webform.
38
Make sure you have added the webform components you wish to validate before adding the validation rule.
39

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

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

    
49
Once you have configured your desired validation rules for the selected webform components, every time a user fills in the webform,
50
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.
51

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

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

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

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

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

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

    
86
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().
87
* $validators - array of validators as supplied by modules implementing hook_webform_validation_validators().
88

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