Drupal 7 将类添加到Drupal7注册表窗体

Drupal 7 将类添加到Drupal7注册表窗体,drupal-7,drupal-theming,drupal-forms,Drupal 7,Drupal Theming,Drupal Forms,所以我一直在使用Drupal7开发一个网站。我想覆盖默认的登录和注册表单。我能够成功地将自定义类添加到登录和密码表单中。但当我想将这些类添加到注册表表单时,问题就开始了 我使用这个钩子函数尝试添加类 function MyTheme_form_user_register_form_alter(&$form, &$formState){ // set classes; $form["#attributes"]["class"] = "form-element";

所以我一直在使用Drupal7开发一个网站。我想覆盖默认的登录和注册表单。我能够成功地将自定义类添加到登录和密码表单中。但当我想将这些类添加到注册表表单时,问题就开始了

我使用这个钩子函数尝试添加类

function MyTheme_form_user_register_form_alter(&$form, &$formState){
    // set classes;
    $form["#attributes"]["class"] = "form-element";
    $form['field_first_name']['und'][0]['value']['#attributes']['class'][] = 'form-element__control';
    $form['field_last_name']['und'][0]['value']['#attributes']['class'][] = 'form-element__control';
    $form['field_developer_organization']['und'][0]['value']['#attributes']['class'][] = 'form-element__control';
    $form['account']['mail']['#attributes']['class'][] = 'form-element__control';
    $form['account']['pass']['pass1']['#attributes']['class'][] = 'form-element__control';
    $form['account']['pass']['pass2']['#attributes']['class'][] = 'form-element__control';
    $form['account']['captcha_response']['#attributes']['class'][] = 'form-element__control';

    // remove descriptions;
    $form['field_first_name']['und'][0]['value']['#description'] = t('');
    $form['field_last_name']['und'][0]['value']['#description'] = t('');
    $form['field_developer_organization']['und'][0]['value']['#description'] = t('');
    $form['account']['mail']['#description'] = t('');
    $form['account']['pass']['pass1']['#description'] = t('');
    $form['account']['pass']['pass2']['#description'] = t('');
    $form['account']['captcha_response']['#description'] = t('');
}
对于firstname、lastname、developer organization、email,成功添加了类,但是对于password字段和captcha字段,没有添加类


可能是什么问题?

在代码片段中,您正在更改表单。它只是核心用户帐户表单字段、自定义配置文件字段和其他基本内容的包装器

尝试用同样的方法修改表单,修改用户名和密码字段的类名

在每个表单的文档中,您可以看到哪些字段可以直接更改,还有哪些表单可以调用它们