2012-10-08 68 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']; 
}