function _form_button_was_clicked

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

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()
_form_builder_handle_input_element in drupal-6.x/includes/form.inc
Populate the #value and #name properties of input elements so they can be processed and rendered. Also, execute any #process handlers attached to a specific element.

File

drupal-6.x/includes/form.inc, line 1090

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;
}