I'm looking for links to authoritative documentation about which one should be used in which cases. When I grep the source, I see both being used in core modules. As such, it makes sense to me to use $form_state['clicked_button'] explicitly when I'm actually expecting a form to have been submitted via a specific button click. If that is fine and proper usage of the FAPI, I don't see any reason to change... but if there's some interplay with the #ajax system that this breaks, I'm happy to change.

Comments

rszrama’s picture

Issue tags: +low-hanging fruit

Tagging.

pcambra’s picture

Issue tags: +dcparisprintmarch

Tagging

rbayliss’s picture

Indeed, it looks like $form_state['clicked_button'] is for buttons only. The only reason it might be worth changing is that it appears to be headed for deprecation. From form_builder() in form.inc:

// Special processing if the triggering element is a button.
    if (isset($form_state['triggering_element']['#button_type'])) {
      // Because there are several ways in which the triggering element could
      // have been determined (including from input variables set by JavaScript
      // or fallback behavior implemented for IE), and because buttons often
      // have their #name property not derived from their #parents property, we
      // can't assume that input processing that's happened up until here has
      // resulted in $form_state['values'][BUTTON_NAME] being set. But it's
      // common for forms to have several buttons named 'op' and switch on
      // $form_state['values']['op'] during submit handler execution.
      $form_state['values'][$form_state['triggering_element']['#name']] = $form_state['triggering_element']['#value'];

      // @todo Legacy support. Remove in Drupal 8.
      $form_state['clicked_button'] = $form_state['triggering_element'];
    }

Probably not worth a big effort to change what's already written, but it seems like we should all get used to using $form_state['triggering_element'] moving forward.

rfay’s picture

Title: Investigate switching $form_state['clicked_button'] to $form_state['triggering_element'] » Replace $form_state['clicked_button'] with $form_state['triggering_element']
Status: Active » Needs review
StatusFileSize
new6.69 KB
rszrama’s picture

Status: Needs review » Fixed

Tested this by using all those buttons and everything seems to work just fine. Thanks for the patch. Committed.

Status: Fixed » Closed (fixed)
Issue tags: -low-hanging fruit, -dcparisprintmarch

Automatically closed -- issue fixed for 2 weeks with no activity.