| 6 xmlrpc_example.module | xmlrpc_example_client_add_submit($form, &$form_state) |
| 7 xmlrpc_example.module | xmlrpc_example_client_add_submit($form, &$form_state) |
| 8 xmlrpc_example.module | xmlrpc_example_client_add_submit($form, &$form_state) |
Submit: query the XML-RPC endpoint for the method xmlrpc_example.add and report the result as a Drupal message.
_state
Parameters
$form:
See also
xmlrpc()
xmlrpc_errno()
xmlrpc_error_msg()
Related topics
1 string reference to 'xmlrpc_example_client_add_submit'
File
- xmlrpc_example/
xmlrpc_example.module, line 421 - 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)))
);
}
}
Login or register to post comments