Hi,

I am generating a form using forms api. I have a text area as below

 array(
 '#type' => 'textarea',
 '#title' => t('Street'),
 '#default_value' => $obj,
 '#required' => ($a4 == 2),
 );

Now, kindly can anyone help me as how to add input format options to this text area.

Comments

wickwood’s picture

did you ever find an answer?

Thanks in advance,
Steve

Thank You Drupal Community for all the help you continue to give me, especially when I need it most!

sansui’s picture

Another person wondering the same :) Found this thread through google search... looked all through forms api, looked at several modules and have been unable to divine this elusive information

sansui’s picture

For weary travelers that may land here through google, these items may help you along:

$form['format'] = filter_form(); - for adding the input format to your form, look it up in api or examples for exact useage

check_markup($your_field, 3, FALSE) - again, look up api or examples for exact useage, but when defining the value for your form, you need to wrap your field in check_markup to process that value with the supplied filter format

muka’s picture

  // to make it work with wysiwyg I've used this
  $form['footer']['my_textarea'] = array(
    '#title' => t('Some Text'),
    '#type' => 'textarea',
    '#default_value' => variable_get('my_textarea', ''),
  );
  $form['footer']['format'] = filter_form(FILTER_FORMAT_DEFAULT, NULL, array('footer'));

sivaji_ganesh_jojodae’s picture

Also #type text_format can be used. It is a text format enabled version of a textarea. See https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#text_format

<?php
  $form['description'] = array(
    '#type' => 'text_format',
    '#title' => t('Description'),
    '#default_value' => $term->description,
    '#format' => $term->format,
    '#weight' => 0,
  );
?>
jedihe’s picture

In Drupal 8, #type => 'text_format' still works. On form submit, the values can be read like this:

public function submitForm(array &$form, FormStateInterface $form_state) {
  $formatted_text = $form_state->getValue('description');
  $only_value = $formatted_text['value'];
  $only_format = $formatted_text['format'];
}