clientside_validation_webform.module 25.1 KB
Newer Older
Jelle Sebreghts's avatar
Jelle Sebreghts committed
1
2
3
4
5
6
7
8
<?php
/**
 * @file
 * Adds clientside validation support for the webform module
 */

function clientside_validation_webform_clientside_validation_webform_alter(&$form, &$form_state, &$js_rules) {
  clientside_validation_webform_after_build_recurse($form['#id'], $form, $form_state, $js_rules);
9
  clientside_validation_webform_add_webform_validation($form['#id'], $form, $form_state, $js_rules);
10

11
12
13
14
15
16
17
  // check for Save Draft button
  if (isset($form['actions']['draft'])) {
    if (!isset($form['actions']['draft']['#attributes']['class'])) {
      $form['actions']['draft']['#attributes']['class'] = array();
    }
    $form['actions']['draft']['#attributes']['class'][0] = 'cancel';
  }
18
19
20
21
22
23
}

function clientside_validation_webform_after_build_recurse($form_id, &$form, &$form_state, &$js_rules) {
  if ($children = array_values(element_children($form))) {
    foreach ($children as $index => $item) {
      $element = $form[$item];
24
25
26
27
28
      $skipvalidation = FALSE;
      if (isset($element['#webform_component']['extra']['exclude_cv']) && $element['#webform_component']['extra']['exclude_cv'] == "1") {
        $skipvalidation = TRUE;
      }
      if (isset($element['#title']) && !$skipvalidation) {
29
        if (isset($element['#type'])) {
30
31
          if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'time' && isset($element['hour']['#name'])) {
            $message = t('Hour in !name field is required.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', '')));
32
            _clientside_validation_set_required($element['hour']['#name'], $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $message);
33
            $message = t('Minute in !name field is required.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', '')));
34
            _clientside_validation_set_required($element['minute']['#name'], $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $message);
35
36
37
          }
          elseif (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'date') {
            $message = t('Month in !name field is required.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', '')));
38
            _clientside_validation_set_required($element['#name'] . '[month]', $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $message);
39
            $message = t('Day in !name field is required.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', '')));
40
            _clientside_validation_set_required($element['#name'] . '[day]', $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $message);
41
            $message = t('Year in !name field is required.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', '')));
42
            _clientside_validation_set_required($element['#name'] . '[year]', $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules, $message);
43
44
45
46
47
48
            if (isset($element['#year_start']) && isset($element['#year_end'])) {
              if (is_numeric($element['#year_start']) && is_numeric($element['#year_end'])) {
                $message = t('The entered date needs to be between the years @start and @end.', array('@start' => $element['#year_start'], '@end' => $element['#year_end']));
                _clientside_validation_set_minmax($element['#name'] . '[year]', $element['#title'], $element['#year_start'], $element['#year_end'], $js_rules, $message);
              }
            }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
            elseif (isset($element['#start_date']) || isset($element['#end_date'])) {
              if (isset($element['#start_date']) && isset($element['#end_date'])) {
                $message = t('The entered date needs to be between the dates @start and @end.', array('@start' => $element['#start_date'], '@end' => $element['#end_date']));
                $start_date = explode('-', $element['#start_date']);
                $end_date = explode('-', $element['#end_date']);
              }
              elseif (isset($element['#start_date'])) {
                $message = t('The entered date needs to be before @start', array('@start' => $element['#start_date']));
                $start_date = explode('-', $element['#start_date']);
                $end_date = '';
              }
              else {
                $message = t('The entered date needs to be before @end', array('@end' => $element['#end_date']));
                $start_date = '';
                $end_date = explode('-', $element['#end_date']);
              }
65
66
              $id = 'webform-component-' . str_replace('_', '-', implode('--', array_slice($element['#parents'], 1)));
              _clientside_validation_set_minmax_date($id, $element['#title'], $start_date, $end_date, $js_rules, $message);
67
68
69
70
            }
          }
          elseif ($element['#type'] == 'checkboxes') {
            $id = '#' . $element['#id'];
71
            _clientside_validation_set_checkboxgroup_minmax($element['#name'], $element['#title'], $id, $js_rules, '', intval($element['#required']));
72
73
          }
          elseif ($element['#type'] == 'select' && $element['#multiple']) {
74
            _clientside_validation_set_required($element['#name'] . '[]', $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules);
75
          }
76
          elseif (isset($element['#name'])) {
77
            _clientside_validation_set_required($element['#name'], $element['#title'], isset($element['#required']) ? $element['#required'] : FALSE, $js_rules);
78
79
          }
        }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
80
        if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'file') {
81
82
83
84
85
          $file_children = element_children($element);
          if (count($file_children) > 0) {
            foreach ($file_children as $child) {
              $file_child = $element[$child];
              if (isset($file_child['#name']) && $file_child['#type'] == 'file') {
86
                $name = $file_child['#name'];
87
                _clientside_validation_set_required($name, $element['#title'], isset($element['#webform_component']['mandatory']) ? (bool)$element['#webform_component']['mandatory'] : FALSE, $js_rules);
88
89
90
91
92
93
                if (isset($element['#webform_component']['extra']['filtering']['types'])) {
                  $extensions = $element['#webform_component']['extra']['filtering']['types'];
                  _clientside_validation_set_extensions($name, $extensions, $js_rules);
                }
              }
            }
94
95
          }
        }
96

97
98
99
100
101
102
103
104
        if (isset($element['#maxlength']) && $element['#maxlength']) {
          $message = t('!name field has a max length of !maxl characters.', array('!name' => variable_get('clientside_validation_prefix', '') . $element['#title'] . variable_get('clientside_validation_suffix', ''), '!maxl' => $element['#maxlength']));
          _clientside_validation_set_minmaxlength($element['#name'], $element['#title'], '', $element['#maxlength'], $js_rules, $message);
        }

        if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'email') {
          _clientside_validation_set_email($element['#name'], $element['#title'], $js_rules);
        }
105
106

        if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'number') {
107
108
109
110
111
112
          if (!$element['#webform_component']['extra']['integer']) {
            _clientside_validation_set_number_decimal($element['#name'], $element['#title'], $element['#webform_component']['extra']['point'], $js_rules);
          }
          else {
            _clientside_validation_set_number($element['#name'], $element['#title'], $js_rules);
          }
113
114
115
116
117
118
119
          if (module_exists('clientside_validation_html5')) {
            _clientside_validation_set_minmax_html5($element['#name'], $element['#title'], $element['#webform_component']['extra']['min'], $element['#webform_component']['extra']['max'], $element['#webform_component']['extra']['step'], $js_rules);
          }
          else {
            _clientside_validation_set_minmax($element['#name'], $element['#title'], $element['#webform_component']['extra']['min'], $element['#webform_component']['extra']['max'], $js_rules);
          }
        }
120
      }
121
122
123
124
125
      if (isset($element['#type']) && $element['#type'] == 'captcha') {
        $settings = clientside_validation_settings_current_form();
        if ($settings['validate_options']['captcha']) {
          $title = _clientside_validation_set_title(isset($element['captcha_widgets']['captcha_response']['#title']) ? $element['captcha_widgets']['captcha_response']['#title'] : $element['#name']);
          $message = t('Wrong answer for !title', array('!title' => $title));
126
127
128
          if (isset($element['captcha_widgets'])) {
            _clientside_validation_set_captcha($element['captcha_widgets']['captcha_response']['#name'], $title, $element['#captcha_validate'], $js_rules, $message);
          }
129
130
        }
      }
131
132
133
134
135
136
137
138
139
140
      clientside_validation_webform_after_build_recurse($form_id, $element, $form_state, $js_rules);
    }
  }
}

/**
 * Support webform_validation
 */

function clientside_validation_webform_add_webform_validation($form_id, &$form, &$form_state, &$js_rules) {
141
  if ($webform_validation_rules = _clientside_validation_webform_webform_validation($form_state['values']['details']['nid'], $form)) {
142
    $checkboxrules = array();
Jelle Sebreghts's avatar
Jelle Sebreghts committed
143
144
145
146
    foreach ($webform_validation_rules as $webform_validation_rule) {
      switch ($webform_validation_rule['validator']) {
        case 'min_length':
          foreach ($webform_validation_rule['components'] as $component) {
147
            $message = t('!name field has a minimum length of !minl characters.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!minl' => $webform_validation_rule['data']));
148
            _clientside_validation_set_minmaxlength($component['element_name'], $component['element_title'], $webform_validation_rule['data'], '', $js_rules, $message);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
149
150
151
152
          }
          break;
        case 'max_length':
          foreach ($webform_validation_rule['components'] as $component) {
153
154
            $message = t('!name field has a maximum length of !maxl characters.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!maxl' => $webform_validation_rule['data']));
            _clientside_validation_set_minmaxlength($component['element_name'], $component['element_title'], '', $webform_validation_rule['data'], $js_rules, $message);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
155
156
          }
          break;
157
158
159
160
161
162
163
        case 'min_words':
          foreach ($webform_validation_rule['components'] as $component) {
            $message = t('!name field must have at least !min words.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!min' => $webform_validation_rule['data']));
            _clientside_validation_set_minmax_words($component['element_name'], $component['element_title'], $webform_validation_rule['data'], "", $js_rules);
          }
          break;
        case 'max_words':
164
          foreach ($webform_validation_rule['components'] as $component) {
165
166
167
168
            $message = t('!name field can not have more than !max words.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', ''), '!max' => $webform_validation_rule['data']));
            _clientside_validation_set_minmax_words($component['element_name'], $component['element_title'], "", $webform_validation_rule['data'], $js_rules);
          }
          break;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
169
        case 'numeric':
170
          $data = $webform_validation_rule['data'];
171
          $range = array('min' => NULL, 'max' => NULL);
172
173
174
175
176
177
178
          if (strpos($data, '|') !== FALSE) {
            list($min, $max) = explode('|', $data);
            if ($min != '' && is_numeric($min)) {
              $range['min'] = (int) $min;
            }
            if ($max != '' && is_numeric($max)) {
              $range['max'] = (int) $max;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
179
180
            }
          }
181
182
183
184
185
          else {
            if ($data != '' && is_numeric($data)) {
                $range['min'] = (int) $data;
            }
          }
186
          foreach ($webform_validation_rule['components'] as $component) {
187
188
189
190
            if (!empty($range['min']) || !empty($range['max'])) {
              _clientside_validation_set_minmax($component['element_name'], $component['element_title'], $range['min'], $range['max'], $js_rules);
            }
            else {
191
              _clientside_validation_set_number_decimal($component['element_name'], $component['element_title'], '.', $js_rules);
192
            }
193
          }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
194
          break;
195
196
        case 'oneofseveral':
        case 'oneoftwo':
197
198
          $names = array();
          $titles = array();
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
          foreach ($webform_validation_rule['components'] as $component) {
            $names[] = $component['element_name'];
            $titles[] = variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '');
          }
          _clientside_validation_set_require_oneof($names, $titles, "", $js_rules);
          break;
        case 'plain_text':
          foreach ($webform_validation_rule['components'] as $component) {
            _clientside_validation_set_plain_text($component['element_name'], $component['element_title'], "", $js_rules);
          }
          break;
        case 'blacklist':
          $message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : '';
          $blacklist = explode(',', $webform_validation_rule['data']);
          $blacklist = array_map('trim', $blacklist);
          foreach ($webform_validation_rule['components'] as $component) {
            _clientside_validation_set_blacklist($component['element_name'], $component['element_title'], $blacklist, $js_rules, $message);
          }
          break;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
218
219
220
        case 'equal':
          $others = $webform_validation_rule['components'];
          $firstone = array_shift($others);
221
          $firstone['form_key'] = implode('][', webform_component_parent_keys(node_load($firstone['nid']), $firstone));
Jelle Sebreghts's avatar
Jelle Sebreghts committed
222
          foreach ($others as $component) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
223
            _clientside_validation_set_equal($component['element_name'], $component['element_title'], $firstone, $js_rules, '', TRUE);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
224
225
226
227
228
229
          }
          break;
        case 'unique':
          $all = $webform_validation_rule['components'];
          while (count($all) > 1) {
            $firstone = array_shift($all);
230
231
            $message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : '';
            _clientside_validation_set_not_equal($firstone['element_name'], $firstone['element_title'], $all, $js_rules, $message, TRUE);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
232
233
234
235
236
237
          }
          break;
        case 'specific_value':
          foreach ($webform_validation_rule['components'] as $component) {
            $value = explode(',', $webform_validation_rule['data']);
            $message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : '';
238
            _clientside_validation_set_specific_value($component['element_name'], $component['element_title'], $value, $js_rules, $message);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
239
240
241
242
          }
          break;
        case 'select_min':
          foreach ($webform_validation_rule['components'] as $component) {
243
244
            $parent_keys = webform_component_parent_keys($form['#node'], $component);
            $form_element = $form['submitted'];
245
            foreach ($parent_keys as $parent_key) {
246
247
              $form_element = $form_element[$parent_key];
            }
248
            if (isset($form_element['#type']) && in_array($form_element['#type'], array('checkbox', 'checkboxes'))) {
249
250
251
252
253
              $checkboxrules[$component['element_name']]['title'] = $component['element_title'];
              $checkboxrules[$component['element_name']]['id'] = '#' . $form_element['#id'];
              $checkboxrules[$component['element_name']]['min'] = $webform_validation_rule['data'];
            }
            else {
254
255
256
257
258
259
260
261
              $el_name = $component['element_name'];
              if (is_string($component['extra'])) {
                $component['extra'] = unserialize($component['extra']);
              }
              if (isset($component['extra']['multiple']) && $component['extra']['multiple']) {
                $el_name .= '[]';
              }
              _clientside_validation_set_minmaxlength_select($el_name, $component['element_title'], $webform_validation_rule['data'], '', $js_rules);
262
            }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
263
264
265
266
          }
          break;
        case 'select_max':
          foreach ($webform_validation_rule['components'] as $component) {
267
268
            $parent_keys = webform_component_parent_keys($form['#node'], $component);
            $form_element = $form['submitted'];
269
            foreach ($parent_keys as $parent_key) {
270
271
              $form_element = $form_element[$parent_key];
            }
272
            if (isset($form_element['#type']) && in_array($form_element['#type'], array('checkbox', 'checkboxes'))) {
273
274
275
276
277
              $checkboxrules[$component['element_name']]['title'] = $component['element_title'];
              $checkboxrules[$component['element_name']]['id'] = '#' . $form_element['#id'];
              $checkboxrules[$component['element_name']]['max'] = $webform_validation_rule['data'];
            }
            else {
278
279
280
281
282
283
284
285
              $el_name = $component['element_name'];
              if (is_string($component['extra'])) {
                $component['extra'] = unserialize($component['extra']);
              }
              if (isset($component['extra']['multiple']) && $component['extra']['multiple']) {
                $el_name .= '[]';
              }
              _clientside_validation_set_minmaxlength_select($el_name, $component['element_title'], '', $webform_validation_rule['data'], $js_rules);
286
            }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
287
288
289
290
          }
          break;
        case 'select_exact':
          foreach ($webform_validation_rule['components'] as $component) {
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
            $parent_keys = webform_component_parent_keys($form['#node'], $component);
            $form_element = $form['submitted'];
            foreach ($parent_keys as $parent_key) {
              $form_element = $form_element[$parent_key];
            }
            if (isset($form_element['#type']) && in_array($form_element['#type'], array('checkbox', 'checkboxes'))) {
              $checkboxrules[$component['element_name']]['title'] = $component['element_title'];
              $checkboxrules[$component['element_name']]['id'] = '#' . $form_element['#id'];
              $checkboxrules[$component['element_name']]['max'] = $webform_validation_rule['data'];
              $checkboxrules[$component['element_name']]['min'] = $webform_validation_rule['data'];
            }
            else {
              $el_name = $component['element_name'];
              if (is_string($component['extra'])) {
                $component['extra'] = unserialize($component['extra']);
              }
              if (isset($component['extra']['multiple']) && $component['extra']['multiple']) {
                $el_name .= '[]';
              }
              _clientside_validation_set_minmaxlength_select($el_name, $component['element_title'], $webform_validation_rule['data'], $webform_validation_rule['data'], $js_rules);
            }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
312
313
314
315
          }
          break;
        case 'validEAN':
          foreach ($webform_validation_rule['components'] as $component) {
316
            $message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : t('Not a valid EAN number.');
317
            _clientside_validation_set_ean($component['element_name'], $component['element_title'], $js_rules, $message);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
318
319
320
321
322
323
          }
          break;
        case 'regex':
          foreach ($webform_validation_rule['components'] as $component) {
            $message = $webform_validation_rule['error_message'];
            $expression = $webform_validation_rule['data'];
324
            _clientside_validation_set_regex($component['element_name'], $component['element_title'], $js_rules, $expression, $message);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
325
326
          }
          break;
327
328
329
330
331
332
        case 'must_be_empty':
          foreach ($webform_validation_rule['components'] as $component) {
            $message = t('!name field must be empty.', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '')));
            _clientside_validation_set_specific_value($component['element_name'], $component['element_title'], array(""), $js_rules, $message);
          }
          break;
333
334
335
336
337
338
339
        default:
          foreach ($webform_validation_rule['components'] as $component) {
            $message = (isset($webform_validation_rule['error_message']) && !empty($webform_validation_rule['error_message'])) ? $webform_validation_rule['error_message'] : t('Invalid value for !name', array('!name' => variable_get('clientside_validation_prefix', '') . $component['element_title'] . variable_get('clientside_validation_suffix', '')));
            $context = array('type' => 'webform', 'rule' => $webform_validation_rule, 'message' => $message);
            drupal_alter('clientside_validation_rule', $js_rules, $component, $context);
          }
          break;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
340
341
      }
    }
342
343
344
345
346
347
348
349
350
    if (!empty($checkboxrules)) {
      foreach ($checkboxrules as $name => $args) {
        if (!isset($args['min'])) {
          $args['min'] = 1;
        }
        if (!isset($args['max'])) {
          $args['max'] = 99;
        }
        _clientside_validation_set_checkboxgroup_minmax($name, $args['title'], $args['id'], $js_rules, '', $args['min'], $args['max']);
351
352
      }
    }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
353
354
  }
}
355

Jelle Sebreghts's avatar
Jelle Sebreghts committed
356
/**
357
 * Retreive webform validation rules
Jelle Sebreghts's avatar
Jelle Sebreghts committed
358
 */
359
function _clientside_validation_webform_webform_validation($nid, $form) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
360
  static $webform_validation_rules;
361
362
  $current_page = $form['details']['page_num']['#value'];
  if (!isset($webform_validation_rules[$nid][$current_page])) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
363
    if (module_exists('webform_validation')) {
364
365
366
367
368
369
370
371
372
373
374
375
      $node_rules = webform_validation_get_node_rules($nid);
      foreach ($node_rules as $rid => $rule) {
        foreach ($rule['components'] as $cid => $component) {
          if ($form['#node']->webform['components'][$component['cid']]['page_num'] != $current_page) {
            unset($node_rules[$rid]['components'][$cid]);
            if (empty($node_rules[$rid]['components'])) {
              unset($node_rules[$rid]);
            }
          }
        }
      }
      $webform_validation_rules[$nid][$current_page] = $node_rules;
376
      // add element name to arrays
377
      clientside_validation_webform_webform_validation_add_names($webform_validation_rules[$nid][$current_page], $form);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
378
379
    }
    else {
380
      $webform_validation_rules[$nid][$current_page] = NULL;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
381
382
    }
  }
383
  return $webform_validation_rules[$nid][$current_page];
384
385
386
387
388
389
390
391
392
393
394
}

function clientside_validation_webform_webform_validation_add_names(&$webform_validation_rules, $form) {
  if ($children = array_values(element_children($form))) {
    foreach ($children as $index => $item) {
      $element = $form[$item];
      if (isset($element['#title'])) {
        if (isset($element['#webform_component']['cid'])) {
          $cid = $element['#webform_component']['cid'];
          foreach ($webform_validation_rules as $i => $webform_validation_rule) {
            foreach ($webform_validation_rule['components'] as $k => $component) {
395
396
              // Fieldsets do not have the name attribute.
              if ($k == $cid && isset($element['#name'])) {
397
398
399
400
401
402
403
404
405
406
                $webform_validation_rules[$i]['components'][$k]['element_name'] = $element['#name'];
                $webform_validation_rules[$i]['components'][$k]['element_title'] = $element['#title'];
              }
            }
          }
        }
      }
      clientside_validation_webform_webform_validation_add_names($webform_validation_rules, $element);
    }
  }
407
}
408
409
410

function clientside_validation_webform_form_webform_component_edit_form_alter(&$form, &$form_state, $form_id) {
  $component = $form_state['build_info']['args'][1];
411
  $form['validation']['exclude_cv'] = array(
412
413
414
415
416
    '#type' => 'checkbox',
    '#title' => 'Exclude from clientside validation',
    '#description' => 'Check this option if you do not want to add clientside validation.',
    '#default_value' => isset($component['extra']['exclude_cv']) ? $component['extra']['exclude_cv'] : FALSE,
  );
Peter Droogmans's avatar
upgrade    
Peter Droogmans committed
417
  array_unshift($form['#submit'], 'clientside_validation_webform_webform_component_edit_form_submit');
418
419
420
}

function clientside_validation_webform_webform_component_edit_form_submit($form, &$form_state) {
421
  // Move setting to extra so it gets saved.
422
  $form_state['values']['extra']['exclude_cv'] = $form_state['values']['validation']['exclude_cv'];
423
}