| 5 form.inc | theme_form($element) |
| 6 form.inc | theme_form( |
| 7 form.inc | theme_form($variables) |
| 8 form.inc | theme_form($variables) |
Returns HTML for a form.
Parameters
$variables: An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #action, #method, #attributes, #children
Related topics
File
- includes/
form.inc, line 3818 - Functions for form and batch generation and processing.
Code
function theme_form($variables) {
$element = $variables['element'];
if (isset($element['#action'])) {
$element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);
}
element_set_attributes($element, array('method', 'id'));
if (empty($element['#attributes']['accept-charset'])) {
$element['#attributes']['accept-charset'] = "UTF-8";
}
// Anonymous DIV to satisfy XHTML compliance.
return '<form' . drupal_attributes($element['#attributes']) . '><div>' . $element['#children'] . '</div></form>';
}
Login or register to post comments
Comments
Missing <form..> tag
I am trying to theme a form, the template for my theme is applied correctly but the form html tag, is missing. Instead all elements are wrapped in tags. This causes my submit button to not do anything. If I remove the theme, everything works correctly. I have the same result using the theme('mytheme', $form) and setting the #theme attribute within the form. Not sure what else to try. Thanks in advance for any help.
had the same problem
I had the same problem and solved it this way:
<?phpfunction your_theme_function($form) {
$variables['element'] = $form;
// render all form elements and/or add custom markup. ** Addition: don't forget to render the hidden inputs form_id and form_build_id, otherwise your form will not work at all
$output = '<div>'.drupal_render($form['elem1']).'</div>';
$output .= drupal_render($form['elem2']);
...
$output .= drupal_render($form['form_build_id']);
$output .= drupal_render($form['form_id']);
// you can also use $output .= drupal_render($form) to print all form elements that have left after manual rendering
$variables['element']['#children'] = $output;
return theme_form($variables);
}
?>
then just simply use
<?phpprint your_theme_function(drupal_get_form('your_form'));
?>
in the place you want to output your modified form - that's all. this way worked for me....
solution works great!
in my case:
<?php
function tcontrol_start_theme($form) {
$variables['element'] = $form;
$output = drupal_render($form);
$variables['element']['#children'] = $output;
return theme_form($variables);
?>
and
<?php$output .= tcontrol_start_theme(drupal_get_form('tcontrol_start_form'));
?>
as a part of a longer output