-1

我在表单挂钩中定义了以下元素:

$form['touchpointdivision'] = array(
    '#type' => 'select',
    '#title' => t('Division'),
    '#options' => $divisions,
    '#required' => TRUE,
    '#ajax' => array(
        'event' => 'change',
        'wrapper' => 'department-wrapper',
        'callback' => 'touchpoints_dept_callback',
        'method' => 'replace'
    )
);

$form['touchpointdepartment'] = array(
    '#type' => 'select',
    '#title' => t('Department'),
    '#prefix' => '<div id="department-wrapper">',
    '#suffix' => '</div>',
    '#options' => _get_departments($selected),
    '#required' => TRUE
);

这是回调:

function touchpoints_dept_callback($form, $form_state){
    return $form('touchpointdepartment');
}

当我在第一个下拉列表中更改项目时,出现以下错误:

“致命错误:函数名称必须是第 203 行 /cmi/sites/all/modules/touchpoints/touchpoints.module 中的字符串”

我在这份声明中遗漏了什么?

4

1 回答 1

0

哇,愚蠢的错误。在回调中,字段名应该在括号中而不是括号中。所以:

function touchpoints_dept_callback($form, $form_state){
    return $form('touchpointdepartment');
}

应该

function touchpoints_dept_callback($form, $form_state){
    return $form['touchpointdepartment'];
}
于 2012-10-08T19:00:26.433 回答