参数传递给Ajax回调函数在Drupal 7的形式API [英] pass arguments to ajax callback function in drupal 7 form api

查看:173
本文介绍了参数传递给Ajax回调函数在Drupal 7的形式API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将参数传递给Ajax回调函数在Drupal 7的形式API

  $元素['字段名'] =阵列(
        #TYPE'=> '文本域',
        #ajax'=>阵列(
          '回调'=> 'ajax_function_name_callback'/%/%/%,
          '方法'=> '更换',
          事件=> '模糊',
              '效果'=> '褪色',
              进步=>阵列(类型=>'活动指示器','信息'=>''),
        ),
    );

功能ajax_function_name_callback($形式,$ form_state)
{
返回 ..
}
 

例如,如果我需要指定表单元素,使用行动阿贾克斯我需要的元素名称传递给函数,使用户的操作和结果返回到另一个元素的形式

我需要传递aruguments这个回调函数'回调'=>'ajax_function_name_callback

功能ajax_function_name_callback($ args1,$ args2,... $形式,$ form_state){返回..}

2 - 以及如何通过形式?

感谢..

如果我不知道什么$ input_name它是从什么oprations genrated我要告诉ajax_'function_name_callback该字段的名称,使

  $元素[$ input_name] =阵列(
        #TYPE'=> '文本域',
        #size'=> '41',
        #ajax'=>阵列(
////////////////////////////////////////////////// ////////////////////////////////
//这里我怎么告诉AJAX调用回这个参数informationvlike这一领域的父母...等
////////////////////////////////////////////////// ///////////////////////////////
              '回调'=> ajax_'function_name_callback,
          '方法'=> '更换',
          事件=> '模糊',
              '效果'=> '褪色',
              进步=>阵列(类型=>'活动指示器','信息'=>''),
        ),
    );


功能ajax_'function_name_callback($ arg_position,$ arg_fieldName,$形式,$ form_state)
{
$形式[$ arg_position] [$ arg_fieldName] [#值] = anotherFunction($形式[$ arg_position] [$ arg_fieldName] [#值]);
返回$形式[$ arg_position] [$ arg_fieldName]
}
 

解决方案

使用该 $ form_state ['triggering_element'] 这将告诉你触发元素的名称和给你所有的属性。

how to pass arguments to Ajax callback function in drupal 7 form api

$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 ..
}

for example if i need to specify form element to make action using ajax i need to pass the element name to the function and make customer operation and return the result to another element form

i need passed aruguments to this callback function 'callback' => 'ajax_function_name_callback'

function ajax_function_name_callback($args1,$args2,...$form,$form_state) { return .. }

2 - and how Through the form ?

thanks..

if i dont know what the $input_name it's genrated from something oprations i need to tell ajax_'function_name_callback the name of this field to make

$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];
}

解决方案

Use this $form_state['triggering_element'] this will tell you the name of the triggering element and give you all of its attributes.

这篇关于参数传递给Ajax回调函数在Drupal 7的形式API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆