Skip navigation
Help

hook_form_alter

6 core.php hook_form_alter(&$form, &$form_state, $form_id)
7 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 can be accessed at $form['#node'].

Note that instead of hook_form_alter(), which is called for all forms, you can also use hook_form_FORM_ID_alter() to alter a specific form. For each module (in system weight order) the general form alter hook implementation is invoked first, then the form ID specific alter implementation is called. After all module hook implementations are invoked, the hook_form_alter() implementations from themes are invoked in the same manner.

Parameters

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

$form_state: A keyed array containing the current state of the form. The arguments that drupal_get_form() was originally called with are available in the array $form_state['build_info']['args'].

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

See also

hook_form_FORM_ID_alter()

Related topics

64 functions implement hook_form_alter()

File

drupal/modules/system/system.api.php, line 1575
Hooks provided by Drupal core and the System module.

Code

function hook_form_alter(&$form, &$form_state, $form_id) {
  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')),
    );
  }
}