Drupal 7 在Drupal7中更改并设置字段的id属性

Drupal 7 在Drupal7中更改并设置字段的id属性,drupal-7,alter,Drupal 7,Alter,谁能帮我修改Drupal7中的字段属性吗。假设我已经创建了一个字段名hello_test,标签为hello。现在我需要更改标签并在我的主题中为template.php文件中的字段设置属性。有人能帮我吗?几天前我遇到了同样的问题。当我在blur和onfocus上设置textfield属性时,它不起作用。确切地说,它正在工作,但我看不到它,因为它被profile2模块的form alter覆盖了 我认为您的FormAlterAPI在profile2模块FormAlterAPI之前加载。所以会被覆盖。

谁能帮我修改Drupal7中的字段属性吗。假设我已经创建了一个字段名hello_test,标签为hello。现在我需要更改标签并在我的主题中为template.php文件中的字段设置属性。有人能帮我吗?几天前我遇到了同样的问题。当我在blur和onfocus上设置textfield属性时,它不起作用。确切地说,它正在工作,但我看不到它,因为它被profile2模块的form alter覆盖了

我认为您的FormAlterAPI在profile2模块FormAlterAPI之前加载。所以会被覆盖。我通过在另一个名称空间中创建自定义表单alter解决了问题

    function yourCustomModuleName_form_profile2_edit_testing_candidate_form_alter(&$form, &$form_state) {

   $form['profile_testing_candidate']["field_candidate_name"] = array(
        "#title" => "Candidate Name",
        "#type" => "textfield",
        "#required" => TRUE,
        "#description" => t(""),
        '#default_value' => 'Given Name',
        '#attributes' => array (
            'onblur' => "if (this.value == '') {this.value = 'Given Name'}",
            'onfocus' => "if (this.value == 'Given Name') {this.value = ''}",
        ),
   );

   $form['profile_testing_candidate']["field_candidate_family_name"] = array(
        "#title" => "",
        "#type" => "textfield",
        "#required" => FALSE,
        "#description" => t(""),
        '#default_value' => 'Family Name',
        '#attributes' => array (
               'onblur' => "if (this.value == '') {this.value = 'Family Name'}",
               'onfocus' => "if (this.value == 'Family Name') {this.value = ''}",
        ),
   );
}