Override the max-width of textareas in content submission forms

description

This snippet allows you to control the max-width (or the number of columns) of text areas in submission forms on your site.

step 1 of 1

  1. Using a text editor like notepad.exe or equivalent, paste the snippet below into your template.php file (remembering to omit the opening and closing PHP tags i.e. <?php. and ?>). If a template.php file doesn't exist, simply create one and include just the opening PHP tag i.e. <?php.
  2. Adjust the column width to suit.
  3. Upload your edited template.php file to your active theme folder and your new layouts will take effect automatically
  4. <?php
    /**
    * This snippet overrides the max column width of
    * text areas in content submission forms.
    *
    */

    function phptemplate_textarea($element) {
     
    $class = array('form-textarea');
      if (
    $element['#cols'] > 30) {
       
    $element['#cols'] = 80; // increase or reduce the max col width value to suit. The default is 80.
     
    }
     
    $cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
     
    _form_set_class($element, $class);
      return
    theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
    }
    ?>

Layout goes wrong when using this textarea override

B3RT13 - November 3, 2007 - 12:01

I just need to change the title and acceskey properties of the textarea properties and decided to use the template override function. But when I use this, the whole layout of the form goes wrong, the title changes, description changes and so on.

I use just this code:

<?php

function phptemplate_textarea($element) {

   
drupal_set_message("['#title'] = " . $element['#title']);
   
drupal_set_message("['#name'] = " . $element['#name']);
   
drupal_set_message("['#description'] = " . $element['#description']);
   
drupal_set_message("['#required'] = " . $element['#required']);

 
$class = array('form-textarea');
 
 
$cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
 
 
_form_set_class($element, $class);
  return
theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
}

?>

Thing is, when printing out the values, these are correct, but the form isnt...

Let me know if you know whats going wrong or if you have a better idea of changing textarea properties

 
 

Drupal is a registered trademark of Dries Buytaert.