7.x system.api.php hook_element_info()

Allows modules to declare their own Form API element types and specify their default values.

This hook allows modules to declare their own form element types and to specify their default values. The values returned by this hook will be merged with the elements returned by hook_form() implementations and so can return defaults for any Form APIs keys in addition to those explicitly mentioned below.

Each of the form element types defined by this hook is assumed to have a matching theme function, e.g. theme_elementtype(), which should be registered with hook_theme() as normal.

For more information about custom element types see the explanation at http://drupal.org/node/169815.

Return value

An associative array describing the element types being defined. The array contains a sub-array for each element type, with the machine-readable type name as the key. Each sub-array has a number of possible attributes:

  • "#input": boolean indicating whether or not this element carries a value (even if it's hidden).
  • "#process": array of callback functions taking $element, $form_state, and $complete_form.
  • "#after_build": array of callback functions taking $element and $form_state.
  • "#validate": array of callback functions taking $form and $form_state.
  • "#element_validate": array of callback functions taking $element and $form_state.
  • "#pre_render": array of callback functions taking $element and $form_state.
  • "#post_render": array of callback functions taking $element and $form_state.
  • "#submit": array of callback functions taking $form and $form_state.
  • "#title_display": optional string indicating if and how #title should be displayed, see theme_form_element() and theme_form_element_label().

See also



Related topics

6 functions implement hook_element_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

contextual_element_info in modules/contextual/contextual.module
Implements hook_element_info().
field_ui_element_info in modules/field_ui/field_ui.module
Implements hook_element_info().
file_element_info in modules/file/file.module
Implements hook_element_info().
filter_element_info in modules/filter/filter.module
Implements hook_element_info().
system_element_info in modules/system/system.module
Implements hook_element_info().

... See full list

1 invocation of hook_element_info()
element_info in includes/common.inc
Retrieves the default properties for the defined element type.


modules/system/system.api.php, line 684
Hooks provided by Drupal core and the System module.


function hook_element_info() {
  $types['filter_format'] = array(
    '#input' => TRUE,
  return $types;


jhodgdon’s picture

In Drupal 6 and before, this was http://api.drupal.org/api/function/hook_elements/6

BartK’s picture

'#theme' specifies an array of theme functions that are called to theme the element.

'#theme_wrappers' specifics an array of theme functions that are called to wrap around the element -- often this is array('form_element')

Reno Greenleaf’s picture

It looks like you can define your own attributes here.

nkschaefer’s picture

I'm in the process of porting my own modules to D7 and had some major frustration with my "#process" callbacks from the D6 version not working properly.

I just realized that Drupal 7 contains a new hook called "hook_process()." That means you need to avoid naming your "#process" callback something like MODULENAME_process() -- Drupal will think that's a different hook (it has something to do with theming).

lukass’s picture

function your_module_element_info() {  
  return array(
    'new_form_type' => array(
      '#input' => TRUE,
      '#tree' => TRUE,
      '#process' => array('_new_form_type_process'),
      '#value_callback' => '_new_form_type_value_callback',

function _new_form_type_value_callback($element, $input = FALSE, &$form_state) {
  if ($input !== FALSE) {
    // Process $input 
  } elseif (!empty($element['#default_value'])) {
    return $element['#default_value'];
markcarver’s picture

It should be mentioned that if the #value key and value is explicitly set here (if even it's NULL) the #value_callback will not work.

jonhattan’s picture

#value_callback is explained in form_builder() docs.

Triss82’s picture

Its more obvious to look for it here so at least a link from here to form_builder() docs could be added.

Reno Greenleaf’s picture

It seems '#pre_render' callbacks accept only one argument, $element.

Begun’s picture

Notes on '#pre_render' callback functions:
1. Callback accepts only one argument, $element
2. Callback must return $element

kristiaanvandeneynde’s picture

lotoo’s picture

we can find more attributes here : form api reference