You are here

function node_limit_limit_form_validate in Node Limit 6

Same name and namespace in other branches
  1. 8 old/node_limit.module \node_limit_limit_form_validate()
  2. 7 node_limit.module \node_limit_limit_form_validate()

Validation hook for node_limit_limit_form.

Allows submodules that are applied to validate their own input.

File

./node_limit.module, line 374
Module to restrict the number of nodes a user or role may create.

Code

function node_limit_limit_form_validate($form_id, &$form_state) {
  if (!is_numeric($form_state['values']['info']['nlimit'])) {
    form_set_error('info][limit', t('Node limits must be an integer'));
  }
  else {
    if (intval($form_state['values']['info']['nlimit']) != floatval($form_state['values']['info']['nlimit'])) {

      // Can't use is_int because is_int("2") == FALSE.
      form_set_error('info][limit', t('Node limits must be an integer'));
    }
    else {
      if (intval($form_state['values']['info']['nlimit']) < NODE_LIMIT_NO_LIMIT) {
        form_set_error('info][limit', t('Node limits cannot be less that %nolimit', array(
          '%nolimit' => NODE_LIMIT_NO_LIMIT,
        )));
      }
    }
  }
  if (trim($form_state['values']['info']['title']) == '') {
    form_set_error('info][title', t('Invalid Node Limit title'));
  }
  foreach ($form_state['values']['node_limit_elements'] as $module => $element) {
    if ($element['applies'] === 1) {

      // They checked the box!
      $result = module_invoke($module, 'node_limit_element_validate', $element['element']);
      if (is_array($result) && isset($result['error'])) {
        $path = $module . '][element';
        if (isset($result['element'])) {
          $path .= '][' . $result['element'];
        }
        form_set_error('node_limit_elements][' . $path, $result['error']);
      }
    }
  }
}