function form_render in Drupal 4
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
29 calls to 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().
- 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
File
- includes/
form.inc, line 523
Code
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;
}
}