【问题标题】:drupal 7 form_alter profile field in group组中的drupal 7 form_alter配置文件字段
【发布时间】:2013-11-07 16:37:17
【问题描述】:

如何访问用户个人资料表单上字段组内的字段?
在我的自定义模块中,我可以使用下面的代码修改帐户名称和电子邮件。

$form['account']['name']['#description'] = 'Enter a username';
$form['account']['mail']['#description'] = 'Enter a valid email address';

这对修改个人信息字段组内的字段不起作用:

$form['Personal information']['profile_name']['#description'] = 'Enter a valid email address';

下面是我尝试访问的数组部分。

[Personal information] => Array
    (
        [#type] => fieldset
        [#title] => Personal information
        [#weight] => 1
        [profile_name] => Array
            (
                [#type] => textfield
                [#title] => First name
                [#default_value] => 
                [#maxlength] => 255
                [#description] => Enter your first name. The content of this field is kept private and will not be shown publicly.
                [#required] => 1
                [#input] => 1

【问题讨论】:

  • 这是什么版本的 Drupal?您是否使用 Profile 2 模块 (drupal.org/project/profile2)?
  • 我认为问题不在于访问字段组内的字段。我的猜测是,有些东西阻止了该功能应用于正确的形式。如果表单有名称并且可能有另一个名称,您可能正在使用规则来应用此更改。你在使用开发模块吗?如果是这样,您是否使用 dpm() 将 $form 打印到屏幕上?我想会有不止一种形式。

标签: drupal drupal-7 drupal-forms


【解决方案1】:

我认为如果您必须在 $form 对象中找到“提交”数组并更改其中的数据。

例如:

$form['account']['mail']['#description'] = 'Enter a valid email address';

拜托这个(在我的情况下):

$form['submitted']['account']['mail']['#description'] = 'Enter a valid email address';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多