Community Documentation

hook_form_alter

5 core.php hook_form_alter($form_id, &$form)
6 core.php hook_form_alter(&$form, &$form_state, $form_id)
7 system.api.php hook_form_alter(&$form, &$form_state, $form_id)
8 system.api.php hook_form_alter(&$form, &$form_state, $form_id)

Perform alterations before a form is rendered.

One popular use of this hook is to add form elements to the node form. When altering a node form, the node object retrieved at from $form['#node'].

Parameters

$form_id: String representing the name of the form itself. Typically this is the name of the function that generated the form.

$form: Nested array of form elements that comprise the form.

Return value

None.

Related topics

▾ 11 functions implement hook_form_alter()

color_form_alter in modules/color/color.module
Implementation of hook_form_alter().
comment_form_alter in modules/comment/comment.module
forum_form_alter in modules/forum/forum.module
Implementation of hook_form_alter().
menu_form_alter in modules/menu/menu.module
Implementation of hook_form_alter(). Add menu item fields to the node form.
multipage_form_example_form_alter in developer/examples/multipage_form_example.module
Implementation of hook_form_alter(). Here, we set up the 'page' field, which keeps track of what stage the form is in.
nodeapi_example_form_alter in developer/examples/nodeapi_example.module
Implementation of hook_form_alter().
node_access_example_form_alter in developer/examples/node_access_example.module
Implementation of hook_form_alter()
node_form_alter in modules/node/node.module
Implementation of hook_form_alter().
path_form_alter in modules/path/path.module
Implementation of hook_form_alter().
taxonomy_form_alter in modules/taxonomy/taxonomy.module
Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node.
upload_form_alter in modules/upload/upload.module

File

developer/hooks/core.php, line 438
These are the hooks that are invoked by the Drupal core.

Code

<?php
function hook_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) {
    $form['workflow']['upload_' . $form['type']['#value']] = array(
      '#type' => 'radios', 
      '#title' => t('Attachments'), 
      '#default_value' => variable_get('upload_' . $form['type']['#value'], 1), 
      '#options' => array(t('Disabled'), t('Enabled')),
    );
  }
}
?>
Login or register to post comments