You are here

function maxlength_node_validate in Maxlength 7.2

Same name and namespace in other branches
  1. 7 maxlength.module \maxlength_node_validate()

Implementation of hook_node_validate().

File

./maxlength.module, line 71
Enables a max length countdown on node body, title and CCK textfields.

Code

function maxlength_node_validate($node, $form, &$form_state) {

  // Core fields, CCK takes care of CCK fields, no need to validate them
  $fields = array(
    'title',
  );
  foreach ($fields as $field) {
    $limit = intval(variable_get('maxlength_' . $field . '_' . $node->type, ''));
    if ($limit > 0) {

      //$form = $a3;

      // line breaks can be stored 2 or more chars, breaking the count.
      $text = $node->{$field};
      $text = str_replace("\r\n", '#', $text);
      $text = str_replace("\n", '#', $text);
      $text = str_replace("\r", '#', $text);
      if (drupal_strlen($text) > $limit) {
        form_set_error($field, t('The @field field has exceeded its maximum number of characters (@limit).', array(
          '@limit' => $limit,
          '@field' => $field,
        )));
      }
    }
  }
}