Remove or prevent css style on specific form elements

by Ghoti   Last Updated June 12, 2019 20:07 PM

Is there a way to create a form element and prevent Drupal from adding classes by default? I have elements that are highly customized. My theme assigns classes by default that ruin these specifically but other elements are fine. The only method I've been able to come up with involves removing certain classes from target elements using javascript (on page load or AJAX trigger). Would be much easier if I could just exclude the css when the element is made in the first place.

Note - I want element specific class exclusion/removal. Simply editing the original css style isn't an optimal solution, as there are other elements that benefit from the theme style.

My demo code below consists of a Drupal form button. The form button will have a callback function. I am trying to make it look just like a simple html button created with markup.


function myModule_form($form, $form_state) {
  $form['button1'] = array(
    '#type' => 'button',
    //'#ajax' => array(
    //  'callback' => 'my_callback_function',

  //only seems to be able to add classes, not remove/omit them
  //$form['button1']['#attributes']['class'] = array('test');

  $form['button2'] = array(
    '#type' => 'markup',
    '#markup' => '<button></button>',
  return $form;

Current output: Image

Tags : 7 theming forms

Related Questions

Updated July 25, 2015 14:03 PM

Updated May 17, 2015 05:03 AM

Updated May 29, 2015 05:03 AM

Updated March 12, 2017 23:07 PM

Updated March 13, 2017 21:07 PM