Same name and namespace in other branches
  1. 4.7.x modules/filter.module \filter_form()
  2. 5.x modules/filter/filter.module \filter_form()
  3. 6.x modules/filter/filter.module \filter_form()

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 calls to 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().

... See full list

File

modules/filter.module, line 721
Framework for handling filtering of content.

Code

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