You are here

function xmlrpc_example_client_form in Examples for Developers 7

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

Returns a form array to take input for two arguments.

Present a form to get two arguments, and make a call to an XML-RPC server using these arguments as input, showing the result in a message.

Related topics

1 string reference to 'xmlrpc_example_client_form'
xmlrpc_example_menu in xmlrpc_example/xmlrpc_example.module
Implements hook_menu().

File

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

Code

function xmlrpc_example_client_form() {
  $form = array();
  $form['explanation'] = array(
    '#markup' => '<div>' . t('This example demonstrates how to make XML-RPC calls with Drupal. <br />The "Request methods" button makes a request to the server and asks for the available list of methods, as a service discovery request. <br/>The "Add integers" and "Subtract integers" use the xmlrpc() function to act as a client, calling the XML-RPC server defined in this same example for some defined methods.<br />An XML-RPC error will result if the result in the addition or subtraction requested is out of bounds defined by the server. These error numbers are defined by the server. <br />The "Add and Subtract" button performs a multicall operation on the XML-RPC server: several requests in a single XML-RPC call.<br />') . '</div>',
  );

  // We are going to call add and subtract methods, and
  // they work with integer values.
  $form['num1'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter an integer'),
    '#default_value' => 2,
    '#size' => 5,
    '#required' => TRUE,
  );
  $form['num2'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter a second integer'),
    '#default_value' => 2,
    '#size' => 5,
    '#required' => TRUE,
  );

  // Include several buttons, each of them calling a different method.
  // This button submits a XML-RPC call to the system.listMethods method.
  $form['information'] = array(
    '#type' => 'submit',
    '#value' => t('Request methods'),
    '#submit' => array(
      'xmlrpc_example_client_request_methods_submit',
    ),
  );

  // This button submits a XML-RPC call to the xmlrpc_example.add method.
  $form['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add the integers'),
    '#submit' => array(
      'xmlrpc_example_client_add_submit',
    ),
  );

  // This button submits a XML-RPC call to the xmlrpc_example.subtract method.
  $form['subtract'] = array(
    '#type' => 'submit',
    '#value' => t('Subtract the integers'),
    '#submit' => array(
      'xmlrpc_example_client_subtract_submit',
    ),
  );

  // This button submits a XML-RPC call to the system.multicall method.
  $form['add_subtract'] = array(
    '#type' => 'submit',
    '#value' => t('Add and Subtract'),
    '#submit' => array(
      'xmlrpc_example_client_multicall_submit',
    ),
  );
  if (variable_get('xmlrpc_example_alter_enabled', FALSE)) {
    $form['overridden'] = array(
      '#type' => 'markup',
      '#markup' => '<div><strong>' . t('Just a note of warning: The <a href="!link">alter form</a> has been used to disable the limits, so you may want to turn that off if you do not want it.', array(
        '!link' => url('examples/xmlrpc/alter'),
      )) . '</strong></div>',
    );
  }
  return $form;
}