public function XmlRpcExampleClientForm::submitSubtract in xmlrpc 8
Submit handler to query xmlrpc_example.subtract.
Submit: query the XML-RPC endpoint for the method xmlrpc_example.subtract and report the result as a Drupal message.
Parameters
array $form: Form array.
\Drupal\Core\Form\FormStateInterface $form_state: Form_state object.
See also
xmlrpc()
xmlrpc_example_client_add_submit()
File
- xmlrpc_example/
src/ Form/ XmlRpcExampleClientForm.php, line 206
Class
- XmlRpcExampleClientForm
- Form demonstrating XML-RPC client.
Namespace
Drupal\xmlrpc_example\FormCode
public function submitSubtract(array &$form, FormStateInterface $form_state) {
$server = $this
->getEndpoint();
$options = [
'xmlrpc_example.subtract' => [
(int) $form_state
->getValue('num1'),
(int) $form_state
->getValue('num2'),
],
];
// Make the xmlrpc request and process the results.
$result = xmlrpc($server, $options);
if ($result === FALSE) {
$this
->messenger()
->addError($this
->t('Error return from xmlrpc(): Error: @errno, Message: @message', [
'@errno' => xmlrpc_errno(),
'@message' => xmlrpc_error_msg(),
]));
}
else {
$this
->messenger()
->addStatus($this
->t('The XML-RPC server returned this response: @response', [
'@response' => print_r($result, TRUE),
]));
}
}