You are here

function webform_validation_manage_rule_validate in Webform Validation 6

Same name and namespace in other branches
  1. 7 webform_validation.admin.inc \webform_validation_manage_rule_validate()

Validation handler to add / edit a rule

File

./webform_validation.admin.inc, line 169
Manages validation rules administration UI

Code

function webform_validation_manage_rule_validate($form, &$form_state) {
  $values = $form_state['values'];
  if ($values['action'] == 'edit') {
    if (!is_numeric($values['ruleid']) || $values['ruleid'] == 0) {
      form_set_error(NULL, t('A problem occurred while editing this rule. Please try again.'));
    }
  }
  $rule_validator = webform_validation_get_validator_info($values['validator']);
  $selected_components = count(array_filter($values['rule_components']));

  // check validator min_components property
  if (isset($rule_validator['min_components']) && $rule_validator['min_components'] > 0) {
    if ($rule_validator['min_components'] > $selected_components) {
      form_set_error('rule_components', format_plural($rule_validator['min_components'], 'You need to select at least @count component', 'You need to select at least @count components'));
    }
  }

  // check validator max_components property
  if (isset($rule_validator['max_components']) && $rule_validator['max_components'] > 0) {
    if ($rule_validator['max_components'] < $selected_components) {
      form_set_error('rule_components', format_plural($rule_validator['max_components'], 'You can select @count component at most', 'You can select @count components at most'));
    }
  }
}