Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为表单元素中的单个组件添加css属性-Drupal_Drupal_Drupal Forms - Fatal编程技术网

为表单元素中的单个组件添加css属性-Drupal

为表单元素中的单个组件添加css属性-Drupal,drupal,drupal-forms,Drupal,Drupal Forms,我有一个drupal表单,需要向表单元素中的组件添加单独的类 也就是说,我需要将class='text'属性添加到'textbox(实际框)'中,并将class='title'属性添加到'textbox title'(#title') 如何执行此操作?对于第一种情况,将类添加到文本字段本身时,请使用以下属性: $form['foo'] = array( '#type' => 'textfield', '#title' => t('Textbox title'), '#at

我有一个drupal表单,需要向表单元素中的组件添加单独的类

也就是说,我需要将class='text'属性添加到'textbox(实际框)'中,并将class='title'属性添加到'textbox title'(#title')


如何执行此操作?

对于第一种情况,将类添加到文本字段本身时,请使用以下属性:

$form['foo'] = array(
  '#type' => 'textfield',
  '#title' => t('Textbox title'),
  '#attributes' => array(
    'class' => array('text'), // change to just 'text' for Drupal 6
  ),
);
对于第二种情况——将类添加到标签中,使用Forms API的运气不佳。相反,您可以使用字段和标签的包装器类将其作为目标:

.form-item-field-foo label {
  /* CSS here */
}

有人已经回答了你的问题
该函数为标题添加class='title'提供了可能性。
但是对于class='text',您应该将theme\u textfield(或theme\u textarea)设置为自己的template.php
从./include/form.inc获取代码

但我建议做主题化所需的自定义表单,而不是所有表单元素。当然,如果客户不要求更改所有表单元素,它可能会在某些地方引发样式冲突等。在实际情况下,不需要更改默认元素。

注意,在D7中,类的内容必须是一个数组,“'class'=>array('text')”