function maxlength_form_alter in Maxlength 7.3
Same name and namespace in other branches
- 5.2 maxlength.module \maxlength_form_alter()
- 5 maxlength.module \maxlength_form_alter()
- 6.2 maxlength.module \maxlength_form_alter()
- 6 maxlength.module \maxlength_form_alter()
- 7 maxlength.module \maxlength_form_alter()
- 7.2 maxlength.module \maxlength_form_alter()
Implements hook_form_alter().
File
- ./
maxlength.module, line 252 - Limit the number of characters in textfields and textareas and shows the amount of characters left.
Code
function maxlength_form_alter(&$form, &$form_state, $form_id) {
// Attach maxlength to node title.
if (isset($form['#node']) && strpos($form_id, '_node_form') !== FALSE && variable_get('maxlength_js_' . $form['#node']->type, FALSE)) {
if (!module_exists('title') || title_field_replacement_enabled('node', $form['#node']->type, 'title') !== TRUE) {
$form['title']['#maxlength_js'] = TRUE;
$form['title']['#maxlength'] = intval(variable_get('maxlength_js_' . $form['#node']->type, ''));
$form['title']['#attributes']['maxlength_js_label'] = array();
$maxlength_js_label = t(variable_get('maxlength_js_label_' . $form['#node']->type, MAXLENGTH_DEFAULT_JS_LABEL));
$form['title']['#attributes']['maxlength_js_label'][] = $maxlength_js_label;
maxlength_pre_render($form['title']);
}
}
}