Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294552

There is no way to make a button element that can use the AJAX functionality

$
0
0

As per this very old forum discussion, creating form element buttons with a type of anything other than type="submit" is not possible as we can see it is written directly into the return value below:

From forms.inc:

/**
 * Theme a form button.
 *
 * @ingroup themeable
 */
function theme_button($element) {
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'] .''. $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'];
  }

  return '<input type="submit"'. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'"') .'id="'. $element['#id'] .'" value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) ." />\n";
}

This code is Drupal 5.9 but also applies to Drupal 6.3.

This code contradicts the Forms API Reference, as well as published print materials as noted in the forum discussion: Forms API Ref: #button_type

This check for #button_type and change to the return value should fix things:

function theme_button($element) {
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'] .''. $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'];
  }

  $element['#button_type'] = (isset($element['#button_type'])) ? $element['#button_type'] : 'submit';

  return '<input type="'. $element['#button_type'] .'"'. (empty($element['#name']) ? '' : 'name="'. $element['#name'] .'"')  .'id="'. $element['#id'].'" value="'. check_plain($element['#value']) .'"'. drupal_attributes($element['#attributes']) ." />\n";
}

Does this make sense? If so, I'll roll patches against 5.9 and 6.3.


Viewing all articles
Browse latest Browse all 294552


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>