For example, I define a FORM element called the Package library start date,
$form [' Starttime_baoyue ']=array( ' #type ' = ' TextField ', ' #title ' =>t (' package libraries start date '), TRUE, );
As shown in the code, there are no styles, except for some CSS styles that Drupal adds by default, such as:
So, the actual work, the front-end to a style sheet, there is a fixed style, then how to add to this element?
It's really simple: just add a line of code:
' #attributes ' = =Array(' class ' = =array(' My_class_name ')),
The complete code for the entire element becomes
$form [' Starttime_baoyue ']=array( ' #type ' = ' TextField ', ' #title ' =>t (' package libraries start date '), TRUE, ' #attributes ' = =Array(' class ' = =array(' My_class ')), );
Refresh the page and look at the final HTML of the element:
How, the style ' My_class ', has been added bar ~
DRUPAL7 Formapi to add CSS styles to elements