You are here

function maxlength_form_alter in Maxlength 6

Same name and namespace in other branches
  1. 5.2 maxlength.module \maxlength_form_alter()
  2. 5 maxlength.module \maxlength_form_alter()
  3. 6.2 maxlength.module \maxlength_form_alter()
  4. 7.3 maxlength.module \maxlength_form_alter()
  5. 7 maxlength.module \maxlength_form_alter()
  6. 7.2 maxlength.module \maxlength_form_alter()

Implemenation of hook_form_alter().

File

./maxlength.module, line 175

Code

function maxlength_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type'])) {
    $type = $form['type']['#value'];
    if ($type . '_node_form' == $form_id) {
      if (strlen(variable_get(MAXLENGTH_NODE_TYPE . $type . '_t', '')) > 0) {
        $limit = intval(variable_get(MAXLENGTH_NODE_TYPE . $type . '_t', ''));
        $form['title']['#maxlength'] = $limit;
        if (drupal_strlen($form['title']['#default_value']) > $limit) {
          $form['title']['#default_value'] = drupal_substr($form['title']['#default_value'], 0, $limit);
          drupal_set_message(t('%title_field_label truncated to %limit characters!', array(
            '%title_field_label' => $form['title']['#title'],
            '%limit' => $limit,
          )), 'error');
        }
      }
    }
  }
}