hook_form_alter

developer/hooks/core.php, line 712

Versions
4.7 – 5
hook_form_alter($form_id, &$form)
6 – 7
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'].

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.

Parameters

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

$form_state A keyed array containing the current state of the form.

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

Related topics

Code

<?php
function hook_form_alter(&$form, $form_state, $form_id) {
  if ('node_type_form' == $form_id) {
    $form['workflow']['upload'] = array(
      '#type' => 'radios',
      '#title' => t('Attachments'),
      '#default_value' => variable_get('upload_'. $form['#node_type']->type, 1),
      '#options' => array(t('Disabled'), t('Enabled')),
    );
  }
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.