【问题标题】:Set a Default Value For Drupal Profile Multiselect Field为 Drupal 配置文件多选字段设置默认值
【发布时间】:2011-06-22 12:26:22
【问题描述】:

我正在使用 Drupal 核心配置文件模块,使用 Profile checkboxes 向用户配置文件添加两个自定义字段。

我需要为这两个字段设置一个默认值,例如,默认选中第一个选项。如何才能做到这一点?我是 Drupal 开发的新手,但任何指导都将不胜感激。

我正在使用 Druapl 6.22、Profile 6.22 和 Profile Checkboxes 6.x-1.2

我搜索并得到了这个:

<?php
function my_module_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'user_profile_form') {
        if(arg(0) == 'user' && arg(1)) {
            $user = user_load(arg(1));
                    //Something wrong is here!!!
            $form['test']['profile_test'][1]['#default_value'] = TRUE; 
        }
    }
}

这不起作用。我不知道如何获得正确的字段。我只需要在这个多选复选框中为第一个选项设置一个默认值。怎么样??

【问题讨论】:

    标签: drupal drupal-6 user-profile


    【解决方案1】:

    您可以使用表单 api 在自定义模块中更改该表单(用于复选框)。尝试在您的自定义模块中使用your_module_form_alter() 更改表单,并为您的任何复选框设置'#default_value' = true。假设您知道如何创建自定义模块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 2019-09-20
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多