filter_form

Versions
4.6
filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT)
4.7 – 6
filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format'))
7
filter_form($selected_format = NULL, $weight = NULL, $parents = array('format'))

Generate a selector for choosing a format in a form.

Parameters

$name The internal name used to refer to the form element.

$value The ID of the format that is currently selected.

Return value

HTML for the form element.

▾ 9 functions call filter_form()

block_box_form in modules/block.module
blog_form in modules/blog.module
Implementation of hook_form().
book_form in modules/book.module
Implementation of hook_form().
comment_admin_edit in modules/comment.module
Menu callback; edit a comment from the administrative interface.
forum_form in modules/forum.module
Implementation of hook_form().
node_example_form in developer/examples/node_example.module
Implementation of hook_form().
page_form in modules/page.module
Implementation of hook_form().
story_form in modules/story.module
Implementation of hook_form().
theme_comment_form in modules/comment.module

Code

modules/filter.module, line 721

<?php
function filter_form($name = 'format', $value = FILTER_FORMAT_DEFAULT) {
  if ($value == FILTER_FORMAT_DEFAULT) {
    $value = variable_get('filter_default_format', 1);
  }
  $formats = filter_formats();

  $extra = l(t('More information about formatting options'), 'filter/tips');

  if (count($formats) > 1) {
    // Multiple formats available: display radio buttons with tips.
    $output = '';
    foreach ($formats as $format) {
      $tips = _filter_tips($format->format, false);

      // TODO: get support for block-level radios so the <br /> is not output?
      $output .= '<div>';
      $output .= '<label class="option"><input type="radio" class="form-radio" name="edit['. $name .']" value="'. $format->format .'"'. ($format->format == $value ? ' checked="checked"' : '') .' /> '. $format->name .'</label>';
      $output .= theme('filter_tips', $tips);
      $output .= '</div>';
    }
    return theme('form_element', t('Input format'), $output, $extra, NULL, _form_get_error($name));
  }
  else {
    // Only one format available: use a hidden form item and only show tips.
    $format = array_shift($formats);
    $output = form_hidden($name, $format->format);
    $tips = _filter_tips(variable_get('filter_default_format', 1), false);
    $output .= form_item(t('Formatting guidelines'), theme('filter_tips', $tips, false, $extra), $extra);
    return $output;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.