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