I want to add .form class to all Drupal forms. How can I add class to all forms by overriding theme function?

  • For what possible reason? If you have a class on every form there's nothing to distinguish one from another - so just use form {}' – Clive Jan 20 '14 at 14:59
  • i am using framework for making theme in drupal. So i need to add ui form class to every form. – Mukeysh Jan 20 '14 at 15:01
  • 1
    @Clive for some mystic reason, Bootstrap theme requires it. – Mołot Jan 20 '14 at 15:23

You can do something like this:

function MYMODULE_OR_THEME_form_alter(&$form, &$form_state, $form_id) {
  $form['#attributes']['class'][] = 'MY_CLASS';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.