Same name and namespace in other branches
  1. 4.7.x developer/examples/node_example.module \node_example_form()
  2. 5.x developer/examples/node_example.module \node_example_form()

Implementation of hook_form().

Now it's time to describe the form for collecting the information specific to this node type. This hook requires us to return some HTML that will be later placed inside the form.

File

developer/examples/node_example.module, line 130
This is an example outlining how a module can be used to define a new node type.

Code

function node_example_form(&$node) {
  $output = '';

  // In order to be able to attach taxonomy terms to this node, we need
  // to display the appropriate form elements.
  if (function_exists('taxonomy_node_form')) {
    $output .= implode('', taxonomy_node_form('node_example', $node));
  }

  // Now we define the form elements specific to our node type.
  $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20);
  $output .= filter_form('format', $node->format);
  $output .= form_textfield(t('Color'), 'color', $node->color, 60, 128);
  $output .= form_textfield(t('Quantity'), 'quantity', $node->quantity, 10, 10);
  return $output;
}