You are here

function _clientside_validation_add_special_rules in Clientside Validation 6

Same name and namespace in other branches
  1. 7 clientside_validation.module \_clientside_validation_add_special_rules()
2 calls to _clientside_validation_add_special_rules()
clientside_validation_form_after_build in ./clientside_validation.module
Regular form + CCK
clientside_validation_webform_after_build in ./clientside_validation.module
Webform.

File

./clientside_validation.module, line 159
Add client side validation to a webform.

Code

function _clientside_validation_add_special_rules(&$js_rules, &$settings, $form) {
  foreach ($js_rules as $key => $rule) {
    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 (isset($rule['daterange'])) {
      $settings['clientsideValidation']['forms'][$form['#id']]['daterangerules'][$key] = array(
        'daterange' => $rule['daterange'],
        'messages' => array(
          'daterange' => $rule['messages']['daterange'],
        ),
      );
      unset($rule['daterange']);
      unset($rule['messages']['daterange']);
      if (empty($rule['messages'])) {
        unset($rule['messages']);
      }
    }
    if (isset($rule['datemin'])) {
      $settings['clientsideValidation']['forms'][$form['#id']]['dateminrules'][$key] = array(
        'daterange' => $rule['datemin'],
        'messages' => array(
          'datemin' => $rule['messages']['datemin'],
        ),
      );
      unset($rule['datemin']);
      unset($rule['messages']['datemin']);
      if (empty($rule['messages'])) {
        unset($rule['messages']);
      }
    }
    if (isset($rule['datemax'])) {
      $settings['clientsideValidation']['forms'][$form['#id']]['datemaxrules'][$key] = array(
        'daterange' => $rule['datemax'],
        'messages' => array(
          'datemax' => $rule['messages']['datemax'],
        ),
      );
      unset($rule['datemax']);
      unset($rule['messages']['datemax']);
      if (empty($rule['messages'])) {
        unset($rule['messages']);
      }
    }
    if (isset($rule['dategrouprequired'])) {
      $settings['clientsideValidation']['forms'][$form['#id']]['daterequiredrules'][$key] = array(
        'required' => $rule['dategrouprequired'],
        'messages' => array(
          'required' => $rule['messages']['dategrouprequired'],
        ),
      );
      unset($rule['dategrouprequired']);
      unset($rule['messages']['dategrouprequired']);
      if (empty($rule['messages'])) {
        unset($rule['messages']);
      }
    }
    if (!empty($rule)) {
      $settings['clientsideValidation']['forms'][$form['#id']]['rules'][$key] = $rule;
    }
  }
}