clientside_validation.module 19.2 KB
Newer Older
Peter Droogmans's avatar
Peter Droogmans committed
1
<?php
Jelle's avatar
Jelle committed
2
// $Id$
Peter Droogmans's avatar
Peter Droogmans committed
3
4
/**
 * @file
5
 * Add client side validation to forms.
Peter Droogmans's avatar
Peter Droogmans committed
6
7
 */

Peter Droogmans's avatar
Peter Droogmans committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * Implements hook_menu().
 */
function clientside_validation_menu() {
  $items['admin/structure/clientside_validation'] = array(
    'title' => 'Clientside Validation',
    'description' => 'Administer clientside validation.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('clientside_validation_admin_settings'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}

function clientside_validation_admin_settings() {
  $form['clientside_validation'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#title' => t('Field name formatting'),
    '#description' => t('You can define the prefix and suffix of the field names in the error messages here.'),
  );
  $form['clientside_validation']['clientside_validation_prefix'] = array(
    '#title' => t('Field name prefix'),
    '#description' => t('The prefix of the field name in the error messages.'),
    '#type' => 'textfield',
    '#default_value' => variable_get('clientside_validation_prefix', ''),
  );
  $form['clientside_validation']['clientside_validation_suffix'] = array(
    '#title' => t('Field name suffix'),
    '#description' => t('The suffix of the field name in the error messages.'),
    '#type' => 'textfield',
    '#default_value' => variable_get('clientside_validation_suffix', ''),
  );
  $form['clientside_validation']['example_image'] = array(
    '#type' => 'item',
    '#title' => t('Example'),
    '#value' => '<img id="clientside_validation_example_image" src="' . base_path() . drupal_get_path('module', 'clientside_validation') . '/errormsg.png" alt="' . t('Error message example') . '" />',
    '#description' => t('Filling in double quotes in both the above fields will give this result.'),
  );

  $form['clientside_validation_min'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#title' => t('Use minified version of jquery.validate.js'),
    '#description' => t('You can use the minified version of the library.'),
  );
  $form['clientside_validation_min']['clientside_validation_use_minified'] = array(
    '#type' => 'radios',
    '#options' => array(
      '0' => t('No'), 
      '1' => t('Yes')
    ),
    '#default_value' => variable_get('clientside_validation_use_minified', 0), 
    '#title' => t('Use minified version?'),
  );
  
  return system_settings_form($form);
}

Peter Droogmans's avatar
Peter Droogmans committed
69
/**
70
 * Implementation of hook_form_alter().
Peter Droogmans's avatar
Peter Droogmans committed
71
 */
72
73
74
75
76
77
78
79
80
81
82
83
84
function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'webform_client_form') !== FALSE) {
    if (isset($form['actions']['previous'])) {
      if (isset($form['actions']['previous']['#attributes'])) {
        if (isset($form['actions']['previous']['#attributes']['class'])) {
          $form['actions']['previous']['#attributes']['class'] .= ' cancel';
        }
        else {
          $form['actions']['previous']['#attributes']['class'] = 'cancel';
        }
      }
      else {
        $form['actions']['previous']['#attributes']['class'] = 'cancel';
85
86
      }
    }
87
    $form['#after_build'][] = 'clientside_validation_webform_after_build';
88
  }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  else {
    switch ($form['#id']) {
      case 'node-form':
      case 'webform-component-edit-form':
        $form['#after_build'][] = 'clientside_validation_form_after_build';
        break;
      default:
        $form['#after_build'][] = 'clientside_validation_form_after_build';
        break;
    }
  }
}

/**
 * Webform.
 */
function clientside_validation_webform_after_build(&$form, &$form_state) {
  $js_rules = array();
  drupal_alter("clientside_validation_webform", $form, $form_state, $js_rules);
Peter Droogmans's avatar
Peter Droogmans committed
108
  if (!empty($js_rules)) {
Jelle's avatar
Jelle committed
109
    $settings['clientsideValidation']['general'] = array(
Peter Droogmans's avatar
Peter Droogmans committed
110
111
112
113
114
115
116
      "errorClass" => "error",
      "wrapper" => "li",
    );
    $settings['clientsideValidation']['forms'][$form['#id']]['settings'] = array(
      "errorContainer" => "#formerrors-" . $form['#id'],
      "errorLabelContainer" => "#formerrors-" . $form['#id'] . " ul",
    );
Jelle's avatar
Jelle committed
117
    foreach ($js_rules as $key => $rule) {
Peter Droogmans's avatar
Peter Droogmans committed
118
119
120
121
122
123
124
125
126
127
128
129
130
131
      if (isset($rule['checkboxgroupminmax'])) {
        $settings['clientsideValidation']['forms'][$form['#id']]['checkboxrules'][$key] = array(
            'checkboxgroupminmax' => $rule['checkboxgroupminmax'],
            'messages' => array('checkboxgroupminmax' => $rule['messages']['checkboxgroupminmax'])
        );
        unset($rule['checkboxgroupminmax']);
        unset($rule['messages']['checkboxgroupminmax']);
        if (empty($rule['messages'])) {
          unset($rule['messages']);
        }
      }
      if (!empty($rule)) {
        $settings['clientsideValidation']['forms'][$form['#id']]['rules'][$key] = $rule;
      }
Peter Droogmans's avatar
Peter Droogmans committed
132
    }
Peter Droogmans's avatar
Peter Droogmans committed
133
134
135
136
137
138
139
    
    if (variable_get('clientside_validation_use_minified', 0) == 0) {
      drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.js');
    }
    else {
      drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.min.js');
    }
Peter Droogmans's avatar
Peter Droogmans committed
140
    drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/clientside_validation.js');
Peter Droogmans's avatar
Peter Droogmans committed
141
142
143
144
145
146
    drupal_add_js($settings, 'setting');
  }
  return $form;
}

/**
147
 * Regular form.
Peter Droogmans's avatar
Peter Droogmans committed
148
149
150
 */
function clientside_validation_form_after_build(&$form, &$form_state) {
  static $js_rules = array();
151
  drupal_alter("clientside_validation_form", $form, $form_state, $js_rules);
Peter Droogmans's avatar
Peter Droogmans committed
152
  if (!empty($js_rules)) {
Jelle's avatar
Jelle committed
153
    $settings['clientsideValidation']['general'] = array(
Peter Droogmans's avatar
Peter Droogmans committed
154
155
156
157
158
159
160
      "errorClass" => "error",
      "wrapper" => "li",
    );
    $settings['clientsideValidation']['forms'][$form['#id']]['settings'] = array(
      "errorContainer" => "#formerrors-" . $form['#id'],
      "errorLabelContainer" => "#formerrors-" . $form['#id'] . " ul",
    );
Jelle's avatar
Jelle committed
161
    foreach ($js_rules as $key => $rule) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
162
163
164
165
166
167
168
169
170
171
172
      if (isset($rule['checkboxgroupminmax'])) {
        $settings['clientsideValidation']['forms'][$form['#id']]['checkboxrules'][$key] = array(
            'checkboxgroupminmax' => $rule['checkboxgroupminmax'],
            'messages' => array('checkboxgroupminmax' => $rule['messages']['checkboxgroupminmax'])
        );
        unset($rule['checkboxgroupminmax']);
        unset($rule['messages']['checkboxgroupminmax']);
        if (empty($rule['messages'])) {
          unset($rule['messages']);
        }
      }
173
174
175
176
177
178
179
180
181
182
183
      if(isset($rule['ajaxCallback'])) {
        $settings['clientsideValidation']['forms'][$form['#id']]['ajaxrules'][$key] = array(
          'ajaxCallback' => $rule['ajaxCallback'],
          'messages' => $rule['messages']
        );
        unset($rule['ajaxCallback']);
        unset($rule['messages']['ajaxCallback']);
        if (empty($rule['messages'])) {
          unset($rule['messages']);
        }
      }
Jelle Sebreghts's avatar
Jelle Sebreghts committed
184
185
186
      if (!empty($rule)) {
        $settings['clientsideValidation']['forms'][$form['#id']]['rules'][$key] = $rule;
      }
Peter Droogmans's avatar
Peter Droogmans committed
187
    }
Peter Droogmans's avatar
Peter Droogmans committed
188
189
190
191
192
193
    if (variable_get('clientside_validation_use_minified', 0) == 0) {
      drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.js');
    }
    else {
      drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/jquery-validate/jquery.validate.min.js');
    }
Peter Droogmans's avatar
Peter Droogmans committed
194
    drupal_add_js(drupal_get_path('module', 'clientside_validation') . '/clientside_validation.js');
Peter Droogmans's avatar
Peter Droogmans committed
195
196
197
    drupal_add_js($settings, 'setting');
  }

198
  return $form;
Peter Droogmans's avatar
Peter Droogmans committed
199
200
}

201
202
203
/**
 * Set validation rule for required fields.
 */
Jelle's avatar
Jelle committed
204
function _clientside_validation_set_required($name, $title, $required, &$js_rules, $message = '') {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
205
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
Peter Droogmans's avatar
Peter Droogmans committed
206
207
  if ($required) {
    $js_rules[$name]['required'] = TRUE;
208
    $js_rules[$name]['messages']['required'] = (empty($message)) ? t('!name field is required.', array('!name' => $title)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
209
210
211
  }
}

212
213
214
/**
 * Set validation rule for number fields.
 */
Jelle's avatar
Jelle committed
215
function _clientside_validation_set_number($name, $title, $decimalpoint, &$js_rules) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
216
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
Peter Droogmans's avatar
Peter Droogmans committed
217
218
219
220
  $js_rules[$name]['digits_negative'] = TRUE;
  $js_rules[$name]['messages']['digits_negative'] = t('!name field accepts only numbers.', array('!name' => $title));
}

221
222
223
/**
 * Set validation rule for decimal fields.
 */
Jelle's avatar
Jelle committed
224
function _clientside_validation_set_number_decimal($name, $title, $decimalpoint, &$js_rules) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
225
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
Peter Droogmans's avatar
Peter Droogmans committed
226
227
228
229
230
231
232
233
234
235
  if ($decimalpoint == '.') {
    $js_rules[$name]['number'] = TRUE;
    $js_rules[$name]['messages']['number'] = t('!name field accepts only numbers (use a \'.\' as decimal point).', array('!name' => $title));
  }
  else {
    $js_rules[$name]['numberDE'] = TRUE;
    $js_rules[$name]['messages']['numberDE'] = t('!name field accepts only numbers (use a \',\' as decimal point).', array('!name' => $title));
  }
}

236
237
238
/**
 * Set validation rule for fields with a minimum and/or a maximum value.
 */
Jelle's avatar
Jelle committed
239
function _clientside_validation_set_minmax($name, $title, $min, $max, &$js_rules, $message = '') {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
240
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
Peter Droogmans's avatar
Peter Droogmans committed
241
242
  if (isset($min) && $min != '' && isset($max) && $max != '') {
    $js_rules[$name]['range'] = array($min, $max);
243
    $js_rules[$name]['messages']['range'] = (empty($message)) ? t('!name field has to be between !min and !max.', array('!name' => $title, '!min' => $min, '!max' => $max)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
244
  }
Jelle's avatar
Jelle committed
245
  elseif (isset($min) && $min != '') {
Peter Droogmans's avatar
Peter Droogmans committed
246
    $js_rules[$name]['min'] = $min;
247
    $js_rules[$name]['messages']['min'] = (empty($message)) ? t('!name field has to be greater than !min.', array('!name' => $title, '!min' => $min)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
248
  }
Jelle's avatar
Jelle committed
249
  elseif (isset($max) && $max != '') {
Peter Droogmans's avatar
Peter Droogmans committed
250
    $js_rules[$name]['max'] = $max;
251
    $js_rules[$name]['messages']['max'] = (empty($message)) ? t('!name field has to be smaller than !max.', array('!name' => $title, '!max' => $max)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
252
253
254
  }
}

255
256
257
/**
 * Set validation rule for fields with a minimum and/or maximum length.
 */
Jelle's avatar
Jelle committed
258
function _clientside_validation_set_minmaxlength($name, $title, $min, $max, &$js_rules, $message = '') {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
259
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
260
261
262
  if($max == 1){
    $max = '';
  }
Peter Droogmans's avatar
Peter Droogmans committed
263
264
  if (isset($min) && $min != '' && isset($max) && $max != '') {
    $js_rules[$name]['rangelength'] = array($min, $max);
265
    $js_rules[$name]['messages']['rangelength'] = (empty($message)) ? t('!name field has to have between !min and !max values.', array('!name' => $title, '!min' => $min, '!max' => $max)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
266
  }
Jelle's avatar
Jelle committed
267
  elseif (isset($min) && $min != '') {
Peter Droogmans's avatar
Peter Droogmans committed
268
    $js_rules[$name]['minlength'] = $min;
269
    $js_rules[$name]['messages']['minlength'] = (empty($message)) ? t('!name field has to have minimal !min values.', array('!name' => $title, '!min' => $min)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
270
  }
Jelle's avatar
Jelle committed
271
  elseif (isset($max) && $max != '') {
Peter Droogmans's avatar
Peter Droogmans committed
272
    $js_rules[$name]['maxlength'] = $max;
273
    $js_rules[$name]['messages']['maxlength'] = (empty($message)) ? t('!name field has to have maximum !max values.', array('!name' => $title, '!max' => $max)) : $message;
Peter Droogmans's avatar
Peter Droogmans committed
274
275
276
  }
}

277
278
279
/**
 * Set validation rule for required fields that must equal a value from an other field.
 */
Jelle's avatar
Jelle committed
280
function _clientside_validation_set_equal($name, $title, $value, &$js_rules) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
281
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
282
283
284
285
286
287
288
  $js_rules[$name]['equalTo'] = ':input[name=\'submitted[' . $value['form_key'] . ']\']';
  $js_rules[$name]['messages']['equalTo'] = t('!name field has to be equal to !firstone.', array('!name' => $title, '!firstone' => $value['name']));
}

/**
 * Set validation rule for fields that can not be equal to a value from an other field.
 */
Jelle's avatar
Jelle committed
289
function _clientside_validation_set_not_equal($name, $title, $value, &$js_rules, $message = '') {
290
  $js_rules[$name]['notEqualTo'] = ':input[name=\'submitted[' . $value['form_key'] . ']\']';
Jelle Sebreghts's avatar
Jelle Sebreghts committed
291
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
292
293
294
295
296
297
298
  $message = empty($message) ? t('!name field has to different from !firstone.', array('!name' => $title, '!firstone' => $value['name'])) : $message;
  $js_rules[$name]['messages']['notEqualTo'] = $message;
}

/**
 * Set validation rule for fields that must be equal to a specific value.
 */
Jelle's avatar
Jelle committed
299
function _clientside_validation_set_specific_value($name, $title, $value, &$js_rules, $message = '') {
300
  $js_rules[$name]['oneOf'] = $value;
Jelle Sebreghts's avatar
Jelle Sebreghts committed
301
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
302
303
304
305
  $message = empty($message) ? t('!name field has to different from !firstone.', array('!name' => $title, '!firstone' => $value['name'])) : $message;
  $js_rules[$name]['messages']['oneOf'] = $message;
}

306
307
308
309
310
311
312
313
314
315
316
/**
 * Set validation rule for fields that consist of one or more of specific values (e.g. string with only a, b and c in it).
 */
function _clientside_validation_set_specific_values($name, $title, $values, &$js_rules, $message = '') {
  $js_rules[$name]['specificVals'] = $values;
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  dpm($values);
  $message = empty($message) ? t('!name field must consist of following elements only: !elements.', array('!name' => $title, '!elements' => implode(', ', $values))) : $message;
  $js_rules[$name]['messages']['specificVals'] = $message;
}

317
318
319
/**
 * Set validation rule for ean number fields.
 */
Jelle's avatar
Jelle committed
320
function _clientside_validation_set_ean($name, $title, &$js_rules, $message = '') {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
321
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
322
323
  $message = empty($message) ? t('!name field is not a valid EAN number.', array('!name' => $title)) : $message;
  $js_rules[$name]['validEAN'] = TRUE;
Peter Droogmans's avatar
Peter Droogmans committed
324
  $js_rules[$name]['messages']['validEAN'] = $message;
Peter Droogmans's avatar
Peter Droogmans committed
325
326
}

327
328
329
/**
 * Set validation rule for fields with regex validation from webform_validation
 */
330
function _clientside_validation_set_regex($name, $title, &$js_rules, $expression, $message = '', $modifiers = "") {
331
332
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  $message = empty($message) ? t('!name field is not a valid EAN number.', array('!name' => $title)) : $message;
333
334
335
336
  $js_rules[$name]['regexMatch'] = array($expression);
  if(!empty($modifiers)) {
    $js_rules[$name]['regexMatch'][] = $modifiers;
  }
337
338
339
  $js_rules[$name]['messages']['regexMatch'] = $message;
}

340
341
342
/**
 * Set validation rule for file fields that must have a certain extension.
 */
Jelle's avatar
Jelle committed
343
function _clientside_validation_set_extensions($name, $extensions, &$js_rules) {
344
345
346
347
348
349
350
351
  $extension_list = preg_replace('#,(?![^,]+,)#', ' or', implode(', ', $extensions));
  $js_rules[$name]['accept'] = implode('|', $extensions);
  $js_rules[$name]['messages']['accept'] = t("Only files with a %exts extension are allowed.", array('%exts' => $extension_list));
}

/**
 * Set validation rule for checkboxes.
 */
Jelle Sebreghts's avatar
Jelle Sebreghts committed
352
353
function _clientside_validation_set_checkboxgroup_minmax($name, $title, $id, &$js_rules, $min = 1, $max = 99) {
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
354
  $js_rules[$name]['checkboxgroupminmax'] = array($min, $max, $id);
Jelle Sebreghts's avatar
Jelle Sebreghts committed
355
  $js_rules[$name]['messages']['checkboxgroupminmax'] = t('!name field is required.', array('!name' => $title));
356
357
358
359
360
}

/**
 * Set validation rule for email fields.
 */
Jelle's avatar
Jelle committed
361
function _clientside_validation_set_email($name, $title, &$js_rules) {
Jelle Sebreghts's avatar
Jelle Sebreghts committed
362
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
363
364
365
366
  $js_rules[$name]['email'] = TRUE;
  $js_rules[$name]['messages']['email'] = t('The value in !name is not a valid email address.', array('!name' => $title));
}

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/**
 * Set validation rule for url fields.
 */
function _clientside_validation_set_url($name, $title, &$js_rules){
  $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  $js_rules[$name]['url'] = TRUE;
  $js_rules[$name]['messages']['url'] = t('The value in !name is not a valid url.', array('!name' => $title));
}

/**
 * Set ajax callback validation.
 */
function _clientside_validation_set_ajax_callback($name, $title, $callback, $params, &$js_rules, $message = '') {
  $expressions = array(
    'fapi_validation_rule_alpha' => array(
      'pattern' => '^[\pL]++$',
      'modifiers' => 'uD',
    ),
    'fapi_validation_rule_alpha_numeric' => array(
      'pattern' => '^[\pL\pN]++$',
      'modifiers' => 'uD',
    ),
    'fapi_validation_rule_ipv4' => array(
      'pattern' => '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
      . '(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$',
      'modifiers' => '',
    ),
    'fapi_validation_rule_alpha_dash' => array(
      'pattern' => '^[-\pL\pN_]+$',
      'modifiers' => 'uD',
    ),
    'fapi_validation_rule_digit' => array(
      'pattern' => '^\d+$',
      'modifiers' => '',
    ),
  );
  switch ($callback) {
    case 'fapi_validation_rule_alpha':
    case 'fapi_validation_rule_alpha_numeric':
    case 'fapi_validation_rule_ipv4':
    case 'fapi_validation_rule_alpha_dash':
    case 'fapi_validation_rule_digit':
    case 'fapi_validation_rule_regexp':
      if($callback == 'fapi_validation_rule_regexp') {
        $expressions['fapi_validation_rule_regexp'] = array(
          'pattern' => substr($params[1][0], 1, strrpos($params[1][0], '/')-1),
          'modifiers' => substr($params[1][0], strrpos($params[1][0], '/')+1, strlen($params[1][0]) - strrpos($params[1][0], '/') + 1),
        );
      }
      $message = t($message, array('%field' => $title));
      _clientside_validation_set_regex($name, $title, $js_rules, $expressions[$callback]['pattern'], $message, $expressions[$callback]['modifiers']);

      break;
    case 'fapi_validation_rule_numeric':
      _clientside_validation_set_number($name, $title, '.', $js_rules);
      break;
    case 'fapi_validation_rule_email':
      _clientside_validation_set_email($name, $title, $js_rules);
      break;
    case 'fapi_validation_rule_length':
      if (count($params) == 1) {
        _clientside_validation_set_minmaxlength($name, $title, '', $params[1][0], $js_rules);
      }
      else if (count($params) == 2) {
        _clientside_validation_set_minmaxlength($name, $title, $params[1][0], $params[1][1], $js_rules);
      }
      break;
    case 'fapi_validation_rule_url':
      _clientside_validation_set_url($name, $title, $js_rules);
      break;
    case 'fapi_validation_rule_chars':
      _clientside_validation_set_specific_values($name, $title, $params[1], $js_rules);
      break;
    case 'fapi_validation_rule_decimal':
      _clientside_validation_set_number_decimal($name, $title, '.', $js_rules);
      break;
    default:
      break;
  }
 /* $title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
  $js_rules[$name][$callback] =  array('callback' => $callback, 'params' => $params);
  $js_rules[$name]['messages'][$callback] = t($message, array('%field' => $title));*/
}

451
452
453
function clientside_validation_drupal_json_encode($var) {
  return str_replace(array('<', '>', '&'), array('\u003c', '\u003e', '\u0026'), json_encode($var));
}