Community Documentation

Theming CCK Input Form

Last updated February 13, 2010. Created by jwolf on October 28, 2007.
Edited by WorldFallz, add1sun, drupal-id.com. Log in to edit this page.

Suppose you create new CCK content type called: product. You can alter how CCK displays content by creating node-product.tpl.php file. Now, how to alter the INPUT FORM?

Drupal's FormAPI will always look for a theme function based on the form id. In the case of node/add or node/edit forms, this id is type_node_form. So you can use the theme override like so:

<?php
function phptemplate_product_node_form($form) {
  global
$user;
 
$vars = array('user' => $user, 'form' => $form);
  return
_phptemplate_callback('product_edit', $vars);
}
?>

You can also go further in making really designer-friendly tpl.php files by doing your drupal_renders in template.php like so:

<?php
function phptemplate_product_node_form($form) {
  global
$user;
 
$vars = array('user' => $user, 'form' => $form);
 
$vars['title'] = drupal_render($form['title']);
 
$vars['body'] = drupal_render($form['body_filter']);
 
// etc
 
return _phptemplate_callback('product_edit', $vars);
}
?>

This will let you have a product_edit.tpl.php like:

<div class="intro">Start your product here</div>
<div class="title"><?php print $title; ?></div>
<div class="body"><?php print $body; ?></div>

Finally, for maximal control, you can unset the FormAPI #title attributes and label your form elements directly in the template file:

<?php
function phptemplate_product_node_form($form) {
  global
$user;
 
$vars = array('user' => $user, 'form' => $form);
  unset(
$form['title']['#title']);
 
$vars['title'] = drupal_render($form['title']);
  unset(
$form['body_filter']['body']['#title']);
 
$vars['body'] = drupal_render($form['body_filter']);
 
// etc
 
return _phptemplate_callback('product_edit', $vars);
}
?>

Note: For D6 and CCK2 see Theme a CCK input form for CCK2.