简体   繁体   English

将类添加到Drupal 7注册表单

[英]Add classes to Drupal 7 register form

So I have been using drupal 7 to develop a website. 所以我一直在使用drupal 7开发一个网站。 I wanted to override the default login and register forms. 我想覆盖默认的登录和注册表格。 I was able to successfully add custom classes to the login and password forms. 我能够成功地将自定义类添加到登录名和密码表单。 But the problem started when I wanted to add those same classes to the register form. 但是,当我想将相同的类添加到注册表单时,问题就开始了。

I used this hook function to try and add the classes 我用这个钩子函数尝试添加类

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

For the firstname, lastname, developer organisation, email, the classes are added successfully, but for the password fields and the captcha fields the classes are not added 对于名字,姓氏,开发者组织,电子邮件,这些类已成功添加,但对于密码字段和验证码字段,则未添加这些类

What could be the issue? 可能是什么问题?

In your code snippet, you're altering the user_register_form() form. 在代码段中,您正在更改user_register_form()表单。 And it's simply a wrapper for the core user account form fields, custom profile fields and other essentials. 它只是核心用户帐户表单字段,自定义配置文件字段和其他必需内容的包装。

Try altering user_account_form() form the same way, to modify class names for username and password fields. 尝试以相同方式更改user_account_form()形式,以修改用户名和密码字段的类名。

And in each form's documentation you can see what fields can be altered directly, and what other forms make calls to them. 在每个表格的文档中,您可以看到可以直接更改哪些字段,以及其他哪些表格可以对其进行调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM