开发者

Drupal filter_form form input

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 =" .var开发者_开发百科iable_get('setup_image_1', 'image_1.jpg'),
    '#required' => TRUE,
  );


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'));    


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.


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;           
        }   
    }


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜