1

我试图让 Drupal 表单显示复选框,但我似乎没有运气。

function multi_reg_pagecreate() {
    $multi_reg_checkbox = multi_reg_checkbox();

    print_r($multi_reg_checkbox);

    $form['multi_reg_checkbox'] = array(
        '#type' => 'checkboxes',
        '#options' => $multi_reg_checkbox,
        '#description' => t('Register for multiple events here')
        );

    return $form;
}

数据格式如下:

Array ( [22] => Test Event Reg [23] => Test Event Reg 2 )

这似乎类似于示例中所说的:

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/6#checkbox

我做错了什么?

编辑:

我在显示的页面上看到了这个:

<form id="multi-reg-pagecreate" accept-charset="UTF-8" method="post" action="/domain/multiple-registration">
<div>
<div class="form-item form-type-checkboxes form-item-multi-reg-checkbox">
<label for="edit-multi-reg-checkbox">Events </label>
<div id="edit-multi-reg-checkbox" class="form-checkboxes"></div>
<div class="description">Register for multiple events here</div>
</div>
<input type="hidden" value="form-t_KSPV9ULp71yMEUHCtDUKV4R3M18M4ie2_M6cj-ZVU" name="form_build_id">
<input type="hidden" value="RzzEFjyCz29CjH9F9PAB5UV9Xq9VBCx8mTY_HppLfiA" name="form_token">
<input type="hidden" value="multi_reg_pagecreate" name="form_id">
</div>
</form>
4

2 回答 2

2
function multi_reg_pagecreate($form, &$form_state) {
    $multi_reg_checkbox = multi_reg_checkbox();
    $form['multi_reg_checkbox'] = array(
        '#title'       => t('Events'),
        '#type'        => 'checkboxes',
        '#options'     => $multi_reg_checkbox,
        '#description' => t('Register for multiple events here')
    );
    return $form;
}

编辑:

选项必须看起来像:

'#options' => array (
    0 => t('Monday'),
    1 => t('Tuesday'),
    2 => t('Wednesday'),
    3 => t('Thursday'),
    4 => t('Friday'),
    5 => t('Saturday'),
    6 => t('Sunday'),
),

或者:

'#options' => drupal_map_assoc(
    array(0,1,2,3,4,5,6)
),

... 好像:

在此处输入图像描述

请从您当前的$multi_reg_checkbox开发输出中发布您的屏幕

于 2013-08-12T13:47:46.977 回答
1

我知道这个问题很老了......但是......你怎么称呼表格?你是从 hook_menu 做的吗?如果是这样:你确定把

'页面回调' => 'drupal_get_form','页面参数' => 数组('multi_reg_pagecreate'),

于 2015-08-04T17:21:21.377 回答