【问题标题】:Drupal 7: AJAX Form Update issueDrupal 7:AJAX 表单更新问题
【发布时间】:2012-10-08 18:10:39
【问题描述】:

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

$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');
}

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

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

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

【问题讨论】:

    标签: drupal-7 drupal-modules drupal-forms


    【解决方案1】:

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

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

    应该是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多