Drupal filter_form form input

2.5k views Asked by At

This drupal form snippet will give me a textarea with user able to change filter to full html/wysiwyg mode.

My Questions: How can I default to to full html mode?

function MY_MODULE_admin() {
  $form = array();

 $form['format'] = filter_form($form->format);

  // MY_MODULE - ** Image 1 **
    $form['MY_MODULE_image_1'] = array(
    '#type' => 'textarea',
    '#title' => t('Image 1'),
    '#default_value' => variable_get('setup_image_1', 'image_1.jpg'),
    '#description' => "Current value =" .variable_get('setup_image_1', 'image_1.jpg'),
    '#required' => TRUE,
  );
4

There are 4 answers

0
Joe Hyde On

For Drupal 7: The best way to handle (or leverage) the Drupal text filter system is to use not 'textarea', but the 'text_format' field type, like this, which will render a textarea with the filter select below:

      $form['holycrap'] = array(
        '#type' => 'text_format',
        '#format' => NULL, // <- Let Drupal handle the default, based upon user role
        '#title' => t('The HTML for the Holy Crap block above the Main Menu.'),
        '#default_value' => variable_get('caplogin_holycrap', _caplogin_holycrap_default_html()),
      );
     return $form;
0
ernie On

This did the trick.

 $form = array();

 $form['carousel_setup_image_1']['accepted_text_1'] = array(
    '#type' => 'textarea',
    '#title' => t('Image 1 - Carousel '),
    '#default_value' => variable_get('carousel_setup_image_1', 'carousel_image_1.jpg'),
    '#description' => "Current value =" .variable_get('carousel_setup_image_1', 'carousel_image_1.jpg'),
  ); 
  $form['carousel_setup_image_1']['format'] = filter_form(2, NULL, array('accepted_text_1_format'));    
0
ernie On
however, I am not sure why $edit['carousel_setup_image_1']['accepted_text_1']) does not contain entered value.

function carousel_setup_block($op = 'list', $delta = 0, $edit = array())
{
       switch($op)
        {

            // case save (save configuration values)       
            case 'save':
            variable_set('carousel_setup_image_1',                
                    $edit['carousel_setup_image_1']['accepted_text_1']);
                break;           
        }   
    }
0
Kevin On

Well there are two ways.

One, you can set that role's default format to Full HTML under Input Formats.

Two, you can say $form['format']['#default_value'] = 2 (I think Full HTML is 2). This will preselect Full HTML.