form_select

Versions
4.6
form_select($title, $name, $value, $options, $description = NULL, $extra = 0, $multiple = FALSE, $required = FALSE)

Format a dropdown menu or scrolling selection box.

It is possible to group options together; to do this, change the format of $options to an associative array in which the keys are group labels, and the values are associative arrays in the normal $options format.

Parameters

$title The label for the form element.

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

$value The key of the currently selected item, or a linear array of keys of all the currently selected items if multiple selections are allowed.

$options An associative array of buttons to display. The keys in this array are button values, while the values are the labels to display for each button.

$description Explanatory text to display after the form item.

$extra Additional HTML to inject into the select element tag.

$multiple Whether the user may select more than one item.

$required Whether the user must select a value before submitting the form.

Return value

A themed HTML string representing the form element.

Related topics

▾ 39 functions call form_select()

aggregator_block in modules/aggregator.module
Implementation of hook_block().
aggregator_form_feed in modules/aggregator.module
aggregator_settings in modules/aggregator.module
archive_page in modules/archive.module
Menu callback; lists all nodes posted on a given date.
blogapi_settings in modules/blogapi.module
book_form in modules/book.module
Implementation of hook_form().
book_outline in modules/book.module
Implementation of function book_outline() Handles all book outline operations.
comment_configure in modules/comment.module
Menu callback; presents the comment settings page.
comment_moderation_form in modules/comment.module
form_weight in includes/common.inc
Format a weight selection menu.
forum_admin_configure in modules/forum.module
Implementation of hook_settings
forum_block in modules/forum.module
Implementation of hook_block().
hook_block in developer/hooks/core.php
Declare a block or set of blocks.
hook_form in developer/hooks/node.php
Display a node editing form.
menu_edit_item_form in modules/menu.module
Present the menu item editing form.
nodeapi_example_nodeapi in developer/examples/nodeapi_example.module
Implementation of hook_nodeapi().
node_admin_nodes in modules/node.module
Generate the content administration overview.
node_configure in modules/node.module
Menu callback; presents general node configuration options.
node_types_configure in modules/node.module
Menu callback; presents each node type configuration page.
poll_form in modules/poll.module
Implementation of hook_form().
profile_form_profile in modules/profile.module
queue_settings in modules/queue.module
queue_view in modules/queue.module
Display a queued node along with voting options for it.
search_admin in modules/search.module
Menu callback; displays the search module settings page.
statistics_block in modules/statistics.module
Implementation of hook_block().
statistics_settings in modules/statistics.module
Implementation of hook_settings().
system_user in modules/system.module
Implementation of hook_user().
system_view_general in modules/system.module
throttle_settings in modules/throttle.module
Implementation of hook_settings().
update_page in ./update.php
user_block in modules/user.module
Implementation of hook_block().
watchdog_overview in modules/watchdog.module
Menu callback; displays a listing of log messages.
_aggregator_page_list in modules/aggregator.module
Prints an aggregator page listing a number of feed items. Various menu callbacks use this function to print their feeds.
_forum_parent_select in modules/forum.module
Returns a select box for available parent terms
_locale_admin_export_screen in includes/locale.inc
User interface for the translation export screen
_locale_admin_import_screen in includes/locale.inc
User interface for the translation import screen
_locale_admin_manage_add_screen in includes/locale.inc
User interface for the language addition screen
_profile_date_field in modules/profile.module
Helper function: output a date selector
_taxonomy_term_select in modules/taxonomy.module

Code

includes/common.inc, line 1319

<?php
function form_select($title, $name, $value, $options, $description = NULL, $extra = 0, $multiple = FALSE, $required = FALSE) {
  $select = '';
  foreach ($options as $key => $choice) {
    if (is_array($choice)) {
      $select .= '<optgroup label="'. check_plain($key) .'">';
      foreach ($choice as $key => $choice) {
        $select .= '<option value="'. check_plain($key) .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
      }
      $select .= '</optgroup>';
    }
    else {
      $select .= '<option value="'. check_plain($key) .'"'. (is_array($value) ? (in_array($key, $value) ? ' selected="selected"' : '') : ($value == $key ? ' selected="selected"' : '')) .'>'. check_plain($choice) .'</option>';
    }
  }
  return theme('form_element', $title, '<select name="edit['. $name .']'. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . ($extra ? ' '. $extra : '') .' id="edit-'. $name .'">'. $select .'</select>', $description, 'edit-'. $name, $required, _form_get_error($name));
}
?>
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.