【发布时间】:2011-05-22 14:13:50
【问题描述】:
如何在 drupal 7 form api 中将参数传递给 Ajax 回调函数
$element['field name'] = array(
'#type' => 'textfield',
'#ajax' => array(
'callback' => 'ajax_function_name_callback'/%/%/%,
'method' => 'replace',
'event' => 'blur',
'effect' => 'fade',
'progress' => array('type' => 'throbber', 'message' => ''),
),
);
function ajax_function_name_callback($form,$form_state)
{
return ..
}
例如,如果我需要指定表单元素以使用 ajax 进行操作,我需要将元素名称传递给函数并进行客户操作并将结果返回到另一个元素表单
我需要将参数传递给这个回调函数 'callback' => 'ajax_function_name_callback'
函数 ajax_function_name_callback($args1,$args2,...$form,$form_state) { return .. }
2 - 又如何通过表格?
谢谢..
如果我不知道 $input_name 它是从某些操作中生成的,我需要告诉 ajax_'function_name_callback 这个字段的名称来生成
$element[$input_name] = array(
'#type' => 'textfield',
'#size' => '41',
'#ajax' => array(
//////////////////////////////////////////////////////////////////////////////////
// here how i tell the ajax call back about this arguments informationvlike parents of this field ... etc
/////////////////////////////////////////////////////////////////////////////////
'callback' => 'ajax_'function_name_callback',
'method' => 'replace',
'event' => 'blur',
'effect' => 'fade',
'progress' => array('type' => 'throbber', 'message' => ''),
),
);
function ajax_'function_name_callback($arg_position,$arg_fieldName,$form,$form_state)
{
$form[$arg_position][$arg_fieldName][#value] = anotherFunction($form[$arg_position][$arg_fieldName][#value]);
return $form[$arg_position][$arg_fieldName];
}
【问题讨论】: