Projet

Général

Profil

Paste
Télécharger (5,14 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform_validation / README.md @ d0ed0aa6

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 (automatically integrates a JavaScript counter if the optional
14
  Maxlength module is installed)
15
- Minimum number of words
16
- Maximum number of words
17
- Equal values on multiple fields
18
- Unique values on multiple fields
19
- Specific value
20
- Require at least one of two fields
21
- Require at least one of several fields
22
- Minimum number of selections required
23
- Maximum number of selections allowed
24
- Exact number of selections required
25
- Plain text (disallow tags)
26
- Regular expression
27
- Must be empty (Anti-Spam: Hide with CSS)
28
- Words blacklist
29
- Must match a username
30

    
31
## Installation
32

    
33
1. Place the module folder in your sites/all/modules folder
34
2. Make sure you have the webform module enabled
35
3. Activate the module via admin/build/modules
36

    
37
## Usage
38

    
39
Once you have installed the module, an extra tab will appear on the node's
40
webform management pages (tab "Edit" in Webform 2.x, tab "Webform" in Webform
41
3.x). This extra tab is labeled "Webform validation". Upon selecting this
42
tab, you can choose to add one of the available validation rules to your
43
webform. Make sure you have added the webform components you wish to validate
44
before adding the validation rule. After clicking the link to add the desired
45
validation rule, you can specify the following details for your rule:
46

    
47
- an administrative name to describe the validation rule
48
- one or more webform components that should be validated against this rule
49
(depending on the chosen rule, you will have to select a specific number of
50
components for the validation rule to work properly).
51

    
52
Depending on the chosen rule, more form fields will be available on the rules
53
form:
54

    
55
- optionally an extra setting to further configure the rule
56
- optionally a custom error message textfield
57

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

    
64
## Adding custom validation rules
65

    
66
The following steps will let you add custom validators through your module:
67

    
68
1. Implement hook hook_webform_validation_validators(). This hook
69
implementation should return an array of validator key => options array
70
entries. See function webform_validation_webform_validation_validators() in
71
webform_validation.validators.inc for a live example. The options array can
72
contain the following configuration keys:
73
   * name (required): name of the validator.
74
   * component types (required): defines which component types can be
75
   validated by this validator. Specify 'all' to allow all types.
76
   * custom_error (optional): define whether a user can specify a custom
77
   error message upon creating the validation rule.
78
   * custom_data (optional): define whether custom data can be added to the
79
   validation rule.
80
   * min_components (optional): define the minimum number of components to be
81
   selected for creating a validation rule.
82
   * max_components (optional): define the maximum number of components to be
83
   selected for creating a validation rule.
84
   * description (optional): provide a descriptive explanation about the
85
   validator.
86
2. Implement hook hook_webform_validation_validate($validator_name, $items,
87
$components, $rule). This hook gets passed 4 parameters, which will allow you
88
to react to your custom validator (or any other validator for that matter).
89
See function webform_validation_webform_validation_validate() in
90
webform_validation.validators.inc for a live example. Explanation about these
91
parameters:
92
    * $validator_name: this is the validator name (i.e. array key as entered
93
    in hook_webform_validation_validators).
94
    * $items: array containing user submitted entries to be validated.
95
    * $components: this array contains the definitions of the webform
96
    components in your form.
97
    * $rule: this array contains the details of your validation rule.
98

    
99
## Additional hooks
100

    
101
The hook hook_webform_validation($type, $op, $data) can be used to react on
102
various webform_validation based actions.
103

    
104
* $type - possible values: 'rule'
105
* $op - possible values: 'add', 'edit', 'delete'
106
* $data - array with rule data in case of $op add/edit, rule id in case of
107
$op delete.
108

    
109
The hook hook_webform_validator_alter(&$validators) can be used to alter the
110
array of validators that is being generated by
111
hook_webform_validation_validators().
112

    
113
* $validators - array of validators as supplied by modules implementing
114
hook_webform_validation_validators().
115

    
116
## Author
117

    
118
Sven Decabooter (https://www.drupal.org/user/35369)
119

    
120
The author can be contacted for paid customizations of this module as well as
121
Drupal consulting and development.