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.
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 