8.2.x form.api.php hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
8.0.x form.api.php hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
8.1.x form.api.php hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
8.3.x form.api.php hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
4.7.x core.php hook_form_alter($form_id, &$form)
5.x core.php hook_form_alter($form_id, &$form)
6.x core.php hook_form_alter(&$form, &$form_state, $form_id)
7.x 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.


$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


Related topics

10 functions implement hook_form_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_form_alter in modules/comment.module
forum_form_alter in modules/forum.module
Implementation of hook_form_alter().
menu_form_alter in modules/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().

... See full list

2 invocations of hook_form_alter()
drupal_get_form in includes/form.inc
Processes a form array and produces the HTML output of a form. If there is input in the $_POST['edit'] variable, this function will attempt to validate it, using drupal_validate_form(), and then submit the form using drupal_submit_form().
upload_js in modules/upload.module
Menu-callback for JavaScript-based uploads.


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


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')),