添加 类 到 Drupal 7 注册表单

Add classes to Drupal 7 register form

所以一直在用drupal 7开发网站。我想覆盖默认的登录和注册表单。我能够成功地将自定义 类 添加到登录名和密码表单中。但是当我想将相同的 类 添加到注册表单时,问题就出现了。

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

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('');
}

名字,姓氏,开发者组织,邮箱,类添加成功,但密码字段和验证码字段类未添加

可能是什么问题?

在您的代码片段中,您正在更改 user_register_form() 表单。它只是核心用户帐户表单字段、自定义配置文件字段和其他必需品的包装器。

尝试以相同的方式更改 user_account_form() 表单,以修改 class 用户名和密码字段的名称。

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