2012-10-08 71 views
-1

我已经在我的形式挂钩确定的以下内容:的Drupal 7:Ajax表单更新问题

$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字符串”

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

回答

0

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

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

应该

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