Skip navigation
Help

_form_button_was_clicked

6 form.inc _form_button_was_clicked($form)
7 form.inc _form_button_was_clicked($element, &$form_state)

Helper function to handle the sometimes-convoluted logic of button click detection.

In Internet Explorer, if ONLY one submit button is present, AND the enter key is used to submit the form, no form value is sent for it and we'll never detect a match. That special case is handled by _form_builder_ie_cleanup().

Related topics

1 call to _form_button_was_clicked()

File

drupal/includes/form.inc, line 1079

Code

function _form_button_was_clicked($form) {
  // First detect normal 'vanilla' button clicks. Traditionally, all
  // standard buttons on a form share the same name (usually 'op'),
  // and the specific return value is used to determine which was
  // clicked. This ONLY works as long as $form['#name'] puts the
  // value at the top level of the tree of $_POST data.
  if (isset($form['#post'][$form['#name']]) && $form['#post'][$form['#name']] == $form['#value']) {
    return TRUE;
  }
  // When image buttons are clicked, browsers do NOT pass the form element
  // value in $_POST. Instead they pass an integer representing the
  // coordinates of the click on the button image. This means that image
  // buttons MUST have unique $form['#name'] values, but the details of
  // their $_POST data should be ignored.
  elseif (!empty($form['#has_garbage_value']) && isset($form['#value']) && $form['#value'] !== '') {
    return TRUE;
  }
  return FALSE;
}