hook_form_BASE_FORM_ID_alter

  1. drupal
    1. 8
    2. 7
Versions
8 – 7 hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id)

Provide a form-specific alteration for shared forms.

Modules can implement hook_form_BASE_FORM_ID_alter() to modify a specific form belonging to multiple form_ids, rather than implementing hook_form_alter() and checking for conditions that would identify the shared form constructor.

Examples for such forms are node_form() or comment_form().

Note that this hook fires after hook_form_FORM_ID_alter() and before hook_form_alter().

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.

See also

hook_form_FORM_ID_alter()

drupal_prepare_form()

Related topics

Code

modules/system/system.api.php, line 1668

<?php
function hook_form_BASE_FORM_ID_alter(&$form, &$form_state, $form_id) {
  // Modification for the form with the given BASE_FORM_ID goes here. For
  // example, if BASE_FORM_ID is "node_form", this code would run on every
  // node form, regardless of node type.

  // Add a checkbox to the node form about agreeing to terms of use.
  $form['terms_of_use'] = array(
    '#type' => 'checkbox', 
    '#title' => t("I agree with the website's terms and conditions."), 
    '#required' => TRUE,
  );
}
?>