更改并设置 drupal 7 中字段的 id 属性

发布于 2025-01-03 05:51:23 字数 116 浏览 0 评论 0原文

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

Can anyone help me how to alter a field attribute in drupal 7. Let say i have created a field name hello_test with label as hello.Now I need to alter the label and set a attribute for the filed in template.php file in my theme.Can anyone help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2025-01-10 05:51:23

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

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

    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 = ''}",
        ),
   );
}

I faced the same problem a few days ago. When I set a textfield attribute onblur and onfocus, it didn't work. To be precise, it was working but I couldn't see it because it was overwritten by a form alter of the profile2 modules.

I think your form alter api loads before a profile2 module form alter api. So gets overwritten. I solved my problem by creating a custom form alter in another namespace.

    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 = ''}",
        ),
   );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文