A nice book page i found by Rashad Majali on Theming Node Forms in Drupal 7
Here is an example of how to theme the layout of node form using the theme engine in Drupal 7. We will theme the article content type, provided by default with Drupal 7.
Suppose that the article content type, has a taxonomy field field_tags. I want to put the taxonomy field in a seperated region called sidebar.
Also the form buttons, will be extracted and printed as $buttons variable, in seperated region.
Please note that Node form columns module can be alternative for this example.
First of all, let's implement hook_theme(). You can implement it in your theme's template.php or your custom theme. In our case we will do it in a custom module. Let's call it MYMODULE.
Our theme output, will be through the template file article-node-form.tpl.php.
<?php
/**
* Implementation of hook_theme().
*/
function MYMODULE_theme($existing, $type, $theme, $path) {
return array(
'article_node_form' => array(
'render element' => 'form',
'path' => drupal_get_path('module', 'MYMODULE'),
'template' => 'article-node-form'
)
);
}
?>
Then, we should define the preprocess function, for the theme hook article_node_form.
Here it will prepare the variables, sent to the template file.
<?php
/**
* Preprocessor for theme('article_node_form').
*/
function template_preprocess_article_node_form(&$variables) {
// nodeformcols is an alternative for this solution.
if (!module_exists('nodeformcols')) {
$variables['sidebar'] = array(); // Put taxonomy fields in sidebar.
$variables['sidebar'][] = $variables['form']['field_tags'];
unset($variables['form']['field_tags']);
// Extract the form buttons, and put them in independent variable.
$variables['buttons'] = $variables['form']['actions'];
unset($variables['form']['actions']);
}
};
?>
After that, create the template page in the module directory.
In or case the template page will be: modules/MYMODULE/article-node-form. And its code :
<?php if($sidebar): ?>
<?php print drupal_render($sidebar); ?>
<?php endif; ?>
<?php if($form): ?>
<?php print drupal_render_children($form); ?>
<?php endif; ?>
<?php if($buttons): ?>
<?php print drupal_render($buttons); ?>
<?php endif; ?>
Please note that we used drupal_render_children($form); in Drupal 7 to render the rest elements of the form.
Finally, create your own CSS styling :)