将参数传递给drupal 7形式api中的ajax回调函数

use*_*851 9 ajax drupal drupal-7

如何在drupal 7形式的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 ..
}
Run Code Online (Sandbox Code Playgroud)

例如,如果我需要指定表单元素以使用ajax进行操作我需要将元素名称传递给函数并进行客户操作并将结果返回到另一个元素表单

我需要通过这个回调函数'callback'=>'ajax_function_name_callback'的结果

function 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];
}
Run Code Online (Sandbox Code Playgroud)

小智 16

使用此选项$form_state['triggering_element']将告诉您触发元素的名称并为其提供所有属性.


Ber*_*dir 4

通过表格。不需要自定义回调。

ajax 回调可以访问表单中的所有信息。例如,您可以添加一个隐藏类型的表单元素(发送到浏览器,例如可以使用 JavaScript 进行更改)或值(仅在内部使用,可以包含任何类型的数据,例如对象,并且用户不能更改)。

如果你能给出你想要做什么的更详细的例子,我可以给你更详细的解释。