5

I wrote a custom form module in that I placed one text area:

I've tried in this way:

$form['message'] = array(
  '#title' => t('Message'),
  '#type' => 'textarea',
  '#format' => 'full_html',
  '#default_value' => isset($ntemplates->message) ? $ntemplates->message : '',
  '#maxlength' => 255,
  '#attributes' => array(
  'class' => array('field_info'),
  'rows' => '5',
  'cols' => '200',
  ),
  '#wysiwyg' => TRUE,
);  

But it doesn't work. How can I integrate WYSIWYG editor in to my text area?

Note: I'm using wysiwyg-7.22 and ckeditor-3.6.6.2. In the basic page body section it's working. I wrote one custom module for form. In this I am unable to integrate wysiwyg editor.

2
  • Correct me of I'm wrong, but as far as I remember it was in the documentation of WYSIWYG module. Or maybe you are not using this module? If so, what are you using?
    – Mołot
    Dec 3 '14 at 8:28
  • I'm using wysiwyg-7.22 and ckeditor-3.6.6.2. In the basic page body section it's working. I wrote one custom module for form. In this I am unable to integrate wysiwyg editor.
    – Manu
    Dec 3 '14 at 9:16
9

Drupal 7 introduces the form element #type text_format, which is a text-format-enabled version of a textarea.

To integrate WYSIWYG into your custom form, just modify the attribute #type of form as:

'#type' => 'text_format'

Note: Tested it with CKEditor v 7.x.

In case if it doesn't work for you, please check your WYSIWYG configuration.

To hide format options, see: How to hide Input Format Options and help text under a textarea?

Above text field type works in Drupal 7 and 8.

12
  • Please add information which WYSIWYG module your code requires. There are many, at least one universal and few dedicated to single editor libraries.
    – Mołot
    Dec 3 '14 at 8:40
  • Tq, I added '#type' => 'text_format' and I configure ckeditor. It shows one select box with formats(like full_html,plain text) in the bottom of text area. Still issue is not resolved.
    – Manu
    Dec 3 '14 at 9:05
  • wysiwyg-7.x-2.2 and ckeditor-3.6.6.2
    – Manu
    Dec 3 '14 at 9:09
  • 1
    Just checked the same in my local.. It works fine.. Pls check your wysiwyg config.. Does the editor works well in add content -> body field? Dec 3 '14 at 9:13
  • Try using drupal.org/project/ckeditor Module version 7.x-1.16 Dec 3 '14 at 9:15
0

Note that stored value from field is an array not string. So to set up and use, do:

  if (($intro = variable_get('groups_intro', NULL)) == NULL){
    $intro = '';
  }
  $form['groups_intro'] = array(
    '#type' => 'text_format',
    '#title' => t('intro'),
    '#default_value'=> $intro['value'],
    '#format' => $intro['format'],
    '#cols' => 200,
    '#rows' => 10,
    '#required' => TRUE,
  );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.