A Drupal form textarea example

Drupal textarea FAQ: How do I create an HTML textarea in a Drupal form (Drupal 6 or Drupal 7)?

Assuming that you're comfortable with creating a Drupal form, you can create a Drupal form textarea as easily as this:

# an html textarea for our drupal form
$form['life_story'] = array(
  '#title' => t('Your Life Story'),
  '#type' => 'textarea',
);

That code creates an HTML textarea with the label "Your Life Story". The textarea is specified with this option in your form declaration:

  '#type' => 'textarea',

(If you're not comfortable with creating a Drupal module or Drupal form, please see my first Drupal form example/tutorial.)

More Drupal textarea form options

You can add quite a few more fields to your Drupal textarea definition to help control how the HTML textarea is rendered. Here are a few additional fields added to our first textarea example:

$form['life_story'] = array(
  '#title' => t('Your Life Story'),
  '#type' => 'textarea',
  '#description' => 'Tell me all about your life',
  '#default_value' => 'First I was born, and then ...',
  '#rows' => 10,
  '#cols' => 60,
  '#resizable' => TRUE,
);

Hopefully those Drupal textarea form fields are self-explanatory, but if not, leave a note in the Comments section below and I'll be glad to add more information here.

You can add even more fields to your Drupal textarea definition. The fields you can add are defined in the grid at this Drupal Form API reference page.

Drupal form textarea example - Summary

I hope this Drupal form textarea example has been helpful. If you have any questions just leave a note in the Comments section below and I'll be glad to help.