Skip to content

Instantly share code, notes, and snippets.

@opdavies
Last active December 29, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opdavies/7689563 to your computer and use it in GitHub Desktop.
Save opdavies/7689563 to your computer and use it in GitHub Desktop.
Add classes to form actions in Drupal 7
<?php
/**
* Implements hook_form_alter().
*/
function MYTHEME_form_alter(&$form) {
// Add additional classes to each form action.
if (isset($form['actions'])) {
$actions = element_children($form['actions']);
foreach ($actions as $action) {
$item = &$form['actions'][$action];
// Add a generic "button" class.
$item['#attributes']['class'][] = 'button';
// Add a type-specific "button-{type}" class (e.g. "button-submit").
$item['#attributes']['class'][] = 'button-' . $action;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment