Fix for AHAH in core: edge case

  1.   // If the form is being rebuilt due to something else than a pressed button,
  2.   // e.g. a select that was changed, then $_POST['op'] will be empty. As a
  3.   // result, Forms API won't be able to detect any pressed buttons. Eventually
  4.   // it will call _form_builder_ie_cleanup(), which will automatically, yet
  5.   // inappropriately assign the first in the form as the clicked button. The
  6.   // reasoning is that since the form has been submitted, a button surely must
  7.   // have been clicked. This is of course an invalid reasoning in the context
  8.   // of AHAH forms.
  9.   // To work around this, we *always* set $form_state['submitted'] to true,
  10.   // this will prevent _form_builder_ie_cleanup() from assigning a wrong
  11.   // button. When a button is pressed (thus $_POST['op'] is set), then this
  12.   // button will still set $form_state['submitted'],
  13.   // $form_state['submit_handlers'] and $form_state['validate_handlers'].
  14.   // This problem does not exist when AHAH is disabled, because then the
  15.   // assumption is true, and then you generally provide a button as an
  16.   // alternative to the AHAH behavior.
  17.   $form_state['submitted'] = TRUE;
  18.   // Continued from the above: when an AHAH update of the form is triggered
  19.   // without using a button, you generally don't want any validation to kick
  20.   // in. A typical example is adding new fields, possibly even required ones.
  21.   // You don't want errors to be thrown at the user until they actually submit
  22.   // their values. (Well, actually you want to be smart about this: sometimes
  23.   // you do want instant validation, but that's an even bigger pain to solve
  24.   // here so I'll leave that for later…)
  25.   if (!isset($_POST['op'])) {
  26.     // For the default "{$form_id}_validate" and "{$form_id}_submit" handlers.
  27.     $form['#validate'] = NULL;
  28.     $form['#submit'] = NULL;
  29.     // For customly set #validate and #submit handlers.
  30.     $form_state['submit_handlers'] = NULL;
  31.     $form_state['validate_handlers'] = NULL;
  32.     // Disable #required and #element_validate validation.
  33.     _ahah_helper_disable_validation($form);
  34.   }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.