如何覆盖 drupal 7 ising 表单 API 中的默认用户配置文件字段?

发布于 2024-11-28 21:38:47 字数 159 浏览 4 评论 0原文

我想知道如何覆盖/更改用户配置文件中的默认字段,例如:按钮“保存”、名称、时区等。 我想更改、删除(因为我不需要它们)其中一些。 为了更改用户配置文件,我使用钩子:hook_form_alter,使用它我设法将自己的字段添加到用户配置文件中。但现在我想更改默认字段。我该怎么做?

I'd like to know how to override/change the default fields in user profile such as: button Save, name, timezone etc.
I'd like to alter, delete('cause i don't need them) some of them.
To alter the user profile i use the hook: hook_form_alter using which i managed to add my own fieldds to user profile. But now i want to alter the default fields. How can i do it?

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

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

发布评论

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

评论(1

情绪操控生活 2024-12-05 21:38:47

使用 hook_form_alter 是可能的,但最好使用 hook_form_FORM_ID_alter

为了能够改变形式,您需要了解数组的结构,了解这一点的最简单方法是安装 Devel 模块。然后,您可以通过将 dpm($form); 放置在 alter 函数中来查看结构。

您可以在自定义模块主题(在template.php 文件中)中使用此函数。

通常用户个人资料 form_id 是 user_profile_form。一个简单的例子是:

    function mymodule_form_user_profile_form_alter(&$form,$form_state,$form_id){
      $form['timezone']['#access'] = FALSE; //remove the "timezone" field from the form (default value is still saved)
      $form['field_somefield']['#weight'] = -50; //move the field up
      $form['actions']['submit']['#value'] = t('Add this content now'); //change the submit button text
    }

有关好的教程,请参阅 Lullabot 教程 此处 (适用于 drupal 6,但对于 d7 的工作方式相同!)。

API: hook_form_FORM_ID_alter

It is possible with the hook_form_alter, though it is better to use hook_form_FORM_ID_alter!

To be able to alter the form you need to know the structure of the arrays, the easiest way to get to know this is by installing the Devel module. Then you can view the structure by placing dpm($form); inside your alter function.

You can use this function on your custom module or in your theme (in template.php file).

Usually user profile form_id is user_profile_form. A simple example would be:

    function mymodule_form_user_profile_form_alter(&$form,$form_state,$form_id){
      $form['timezone']['#access'] = FALSE; //remove the "timezone" field from the form (default value is still saved)
      $form['field_somefield']['#weight'] = -50; //move the field up
      $form['actions']['submit']['#value'] = t('Add this content now'); //change the submit button text
    }

For a good tutorial see the Lullabot tutorial here (is for drupal 6 but works the same way for d7!).

API: hook_form_FORM_ID_alter

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