Same name and namespace in other branches
  1. 6.x-1.x xmlrpc_example/xmlrpc_example.module \xmlrpc_example_client_add_submit()

Submit handler to query xmlrpc_example.add.

Submit: query the XML-RPC endpoint for the method xmlrpc_example.add and report the result as a Drupal message.

Parameters

array $form: Form array.

array $form_state: Form_state array.

See also

xmlrpc()

xmlrpc_errno()

xmlrpc_error_msg()

Related topics

1 string reference to 'xmlrpc_example_client_add_submit'
xmlrpc_example_client_form in xmlrpc_example/xmlrpc_example.module
Returns a form array to take input for two arguments.

File

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

Code

function xmlrpc_example_client_add_submit($form, &$form_state) {

  // First define the endpoint of the XML-RPC service, in this case is our
  // own server.
  $server = url($GLOBALS['base_url'] . '/xmlrpc.php', array(
    'external' => TRUE,
  ));

  // Then we should define the method to call. xmlrpc() requires that all the
  // information related to the called method is passed as an array in the form
  // of 'method_name' => arguments_array
  $options = array(
    'xmlrpc_example.add' => 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(),
    )), 'error');
  }
  else {
    drupal_set_message(t('The XML-RPC server returned this response: @response', array(
      '@response' => print_r($result, TRUE),
    )));
  }
}