form_render

Versions
4.7
form_render(&$elements)

Renders a HTML form given a form tree. Recursively iterates over each of the form elements, generating HTML code. This function is usually called from within a theme. To render a form from within a module, use drupal_get_form().

Parameters

$elements The form tree describing the form.

Return value

The rendered HTML form.

Related topics

▾ 31 functions call form_render()

drupal_get_form in includes/form.inc
Processes a form array and produces the HTML output of a form. If there is input in the $_POST['edit'] variable, this function will attempt to validate it, using drupal_validate_form(), and then submit the form using drupal_submit_form().
form_render in includes/form.inc
Renders a HTML form given a form tree. Recursively iterates over each of the form elements, generating HTML code. This function is usually called from within a theme. To render a form from within a module, use drupal_get_form().
theme_aggregator_page_list in modules/aggregator.module
theme_archive_browse_form in modules/archive.module
Form theme function; displays the archive date navigation form inline.
theme_block_admin_display in modules/block.module
Theme main block administration form submission.
theme_book_admin_table in modules/book.module
theme_comment_admin_overview in modules/comment.module
theme_comment_controls in modules/comment.module
theme_filter_admin_order in modules/filter.module
Theme filter order configuration form.
theme_filter_admin_overview in modules/filter.module
theme_locale_admin_manage_screen in includes/locale.inc
Theme the locale admin manager form.
theme_multipage_form_example_node_form in developer/examples/multipage_form_example.module
theme_node_admin_nodes in modules/node.module
Theme node administration overview.
theme_node_filters in modules/node.module
Theme node administraton filter selector.
theme_node_filter_form in modules/node.module
Theme node administration filter form.
theme_node_form in modules/node.module
theme_node_search_admin in modules/node.module
theme_poll_view_voting in modules/poll.module
Themes the voting form for a poll.
theme_search_block_form in modules/search.module
Theme the block search form.
theme_search_theme_form in modules/search.module
Theme the theme search form.
theme_system_modules in modules/system.module
theme_system_themes in modules/system.module
theme_system_theme_select_form in modules/system.module
theme_upload_form_current in modules/upload.module
Theme the attachments list.
theme_upload_form_new in modules/upload.module
Theme the attachment form. Note: required to output prefix/suffix.
theme_user_admin_new_role in modules/user.module
theme_user_admin_perm in modules/user.module
theme_user_pass in modules/user.module
theme_watchdog_form_overview in modules/watchdog.module
theme_weight in includes/form.inc
Format a weight selection menu.
upload_js in modules/upload.module
Menu-callback for JavaScript-based uploads.

Code

includes/form.inc, line 523

<?php
function form_render(&$elements) {
  if (!isset($elements)) {
    return NULL;
  }
  $content = '';
  uasort($elements, "_form_sort");
  if (!isset($elements['#children'])) {
    $children = element_children($elements);
    /* Render all the children that use a theme function */
    if (isset($elements['#theme']) && !$elements['#theme_used']) {
      $elements['#theme_used'] = TRUE;

      $previous = array();
      foreach (array('#value', '#type', '#prefix', '#suffix') as $key) {
        $previous[$key] = isset($elements[$key]) ? $elements[$key] : NULL;
      }
      // If we rendered a single element, then we will skip the renderer.
      if (empty($children)) {
        $elements['#printed'] = TRUE;
      }
      else {
        $elements['#value'] = '';
      }
      $elements['#type'] = 'markup';

      unset($elements['#prefix'], $elements['#suffix']);
      $content = theme($elements['#theme'], $elements);

      foreach (array('#value', '#type', '#prefix', '#suffix') as $key) {
        $elements[$key] = isset($previous[$key]) ? $previous[$key] : NULL;
      }
    }
    /* render each of the children using form_render and concatenate them */
    if (!isset($content) || $content === '') {
      foreach ($children as $key) {
        $content .= form_render($elements[$key]);
      }
    }
  }
  if (isset($content) && $content !== '') {
    $elements['#children'] = $content;
  }

  // Until now, we rendered the children, here we render the element itself
  if (!isset($elements['#printed'])) {
    $content = theme(($elements['#type']) ? $elements['#type']: 'markup', $elements);
    $elements['#printed'] = TRUE;
  }

  if (isset($content) && $content !== '') {
    $prefix = isset($elements['#prefix']) ? $elements['#prefix'] : '';
    $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : '';
    return $prefix . $content . $suffix;
  }
}
?>
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.