You are here

function xmlrpc_example_client_add_submit in Examples for Developers 6

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

Submit: query the xmlrpc endpoint for the method xmlrpc_example.add and report the result.

_state

Parameters

$form:

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
Present a form that makes use of xmlrpc services to add or subtract.

File

xmlrpc_example/xmlrpc_example.module, line 264
This is an example of how to implement an XML-RPC server by registering callbacks to specific methods and how to make xmlrpc calls using the builtin xmlrpc() factory provided by Drupal.

Code

function xmlrpc_example_client_add_submit($form, &$form_state) {

  // First define the endpoint of the xmlrcp service, in this case is our
  // own server.
  $server = url($GLOBALS['base_url'] . "/xmlrpc.php");

  // Then we should pass the method and the arguments to the xmlrpc client.
  // Make the xmlrpc request and process the results.
  $result = xmlrpc($server, 'xmlrpc_example.add', (int) $form_state['values']['num1'], (int) $form_state['values']['num2']);
  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 XMLRPC server returned this response: @response", array(
      '@response' => print_r($result, TRUE),
    )));
  }
}