【问题标题】:Alter and set a id attribute for a field in drupal 7在 drupal 7 中更改并设置字段的 id 属性
【发布时间】:2012-02-08 14:03:37
【问题描述】:

谁能帮我在drupal 7中更改字段属性。假设我创建了一个字段名称hello_test,标签为hello。现在我需要更改标签并为template.php文件中的字段设置一个属性在我的主题中。任何人都可以帮助我

【问题讨论】:

    标签: drupal-7 alter


    【解决方案1】:

    几天前我遇到了同样的问题。当我设置文本字段属性 onblur 和 onfocus 时,它不起作用。准确地说,它正在工作,但我看不到它,因为它被 profile2 模块的表单更改覆盖了。

    我认为您的表单 alter api 在 profile2 模块表单 alter api 之前加载。所以被覆盖。我通过在另一个命名空间中创建自定义表单 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 = ''}",
            ),
       );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-16
      相关资源
      最近更新 更多