Drupal - Attach WYSIWYG to Drupal Form

The wysiwyg module is tied to the input format system.

Use '#type' => 'text_format' when defining your text area.


You should use type = 'text_format' instead of text area. and format = 'editor_format'. The code will look like this.

$form['description'] = array(
  '#type' => 'text_format',
  '#title' => t('Description'),
  '#format' => 'full_html' //the format used for editor.
);

Here is mine:

$form['my_module_my_form_my_field'] = array(
  '#type' => 'text_format',
  '#title' => t('Awesome title'),
  '#format' => isset($edit['format']) ? $edit['format'] : NULL,
  '#base_type' => 'textarea',
  '#default_value' => variable_get('my_module_my_form_my_field', '')['value'],
  '#description' => t("Awesome description."),
  '#required' => FALSE,
  '#maxlength' => 500,
);

I had to add the ['value'] to the #default_value cause it wasn't being loaded after saved.

7x Form API Reference

Tags:

Forms

Wysiwyg

7