Disable Resizable Textarea Drupal 6

Drupal 6 allows textareas to be re-sizable and this may be a useful or annoying feature depending on how you look at it.

It may be useful since you are allowed to change the size on the fly to suit your needs and may be helpful when adding a lot of content at one time.

It may be a nuisance since an extra image (grippie.png) has to be loaded from the server to provide that functionality.

Disable all resizable textareas

To disable all resizable textareas, add the following code to the template.php file which resides in your theme folder. If template.php does not exist, then create it.

<?php
 
function phptemplate_textarea($element)
{
  $element['#resizable'] = false ;
  return theme_textarea($element);
}
 
?>

Remember to clear your cache. Your textareas should now have no resize functionality.

Disable resizable textareas on non-admin screens only

For an even better result, how about disabling resizable textareas for non-admin users only? This is good since admins are usually the ones that add large content each time so the resize option may be good for them. Other users usually only add comments to articles so a resizable textarea is usually overkill.

To perform this decision, we add a simple PHP If-Else Statement to our original code:

<?php
 
function phptemplate_textarea($element)
{
  if (user_access('administer nodes'))
    $element['#resizable'] = true ;
  else
    $element['#resizable'] = false ;
 
  return theme_textarea($element);
}
 
?>

With this code, we check if the user has the "administer nodes" permission and if they do, it leaves the resize option intact. For all other users, resizing is disabled.

Benefits of disabling resizing

At the very least, it will improve page load times since an extra HTTP request (for the image) is avoided. It also avoids confusion for people who don't know what it is for. It plain and simple removes functionality that isn't necessary for some users.

We hope this tutorial has been helpful to you.



Ashish said:

May 3, 2011 at 5:48 am

This is removing my Body text area



vincent said:

May 12, 2011 at 7:07 pm

You are indeed right! The code will remove the body field when adding a node (for example) if the user does not have the permission specified. You may use the code below instead which fixes that problem:

function phptemplate_textarea($element)
{
    if (user_is_logged_in())
        $element['#resizable'] = true ;
    else
        $element['#resizable'] = false ;
 
    return theme_textarea($element);
}

The idea is that once a user is logged in, they will get the resizable box. This approach works best on a site with mostly anonymous users and where the anonymous users are only allowed to make comments (things that do not require a Body field).

Thank Tutorial Arena for This Tutorial.
Show your appreciation with a +1...