xmlrpc_example_client_multicall_submit

7 xmlrpc_example.module xmlrpc_example_client_multicall_submit($form, &$form_state)
8 xmlrpc_example.module xmlrpc_example_client_multicall_submit($form, &$form_state)

Submit a multicall request: query the XML-RPC endpoint for the methods xmlrpc_example.add and xmlrpc_example.subtract and report the result as a Drupal message. Drupal's XML-RPC client builds the system.multicall request automatically when there is more than one method to call.

_state

Parameters

$form:

See also

xmlrpc()

xmlrpc_errno()

xmlrpc_error_msg()

xmlrpc_example_client_multicall_submit()

Related topics

1 string reference to 'xmlrpc_example_client_multicall_submit'

File

xmlrpc_example/xmlrpc_example.module, line 502
Module file for xmlrpc_example module.

Code

function xmlrpc_example_client_multicall_submit($form, &$form_state) {
  $server = url($GLOBALS['base_url'] . '/xmlrpc.php', array('external' => TRUE));

  /*
   * Drupal's built-in xmlrpc server supports the system.multicall method.
   *
   * To make a multicall request, the main invoked method should be the
   * function 'system.multicall', and the arguments to make this call must be
   * defined as an array of single method calls, being the array keys the
   * service methods to be called, and the array elements the method arguments.
   *
   * See the code below this comment as example.
   */

  // Build an array of several calls, Drupal's xmlrpc built-in support will
  // construct the correct system.multicall request for the server.
  $options = array(
    'xmlrpc_example.add' => array(
      (int) $form_state['values']['num1'],
      (int) $form_state['values']['num2'],
    ), 
    'xmlrpc_example.subtract' => array(
      (int) $form_state['values']['num1'],
      (int) $form_state['values']['num2'],
    ),
  );
  // Make the xmlrpc request and process the results.
  $result = xmlrpc($server, $options);

  if ($result === FALSE) {
    drupal_set_message(
      t('Error return from xmlrpc(): Error: @errno, Message: @message', 
      array('@errno' => xmlrpc_errno(), '@message' => xmlrpc_error_msg()))
    );
  }
  else {
    drupal_set_message(
      t('The XML-RPC server returned this response: <pre>@response</pre>', 
      array('@response' => print_r($result, TRUE)))
    );
  }
}
Login or register to post comments