5 * Administrative page callbacks for the httprl module.
9 * Form definition; general settings.
11 function httprl_admin_settings_form() {
12 $form['httprl_server_addr'] = array(
13 '#type' => 'textfield',
14 '#title' => t('IP Address to send all self server requests to'),
15 '#default_value' => variable_get('httprl_server_addr', FALSE
),
16 '#description' => t('If left blank it will use the same server as the request. If set to -1 it will use the host name instead of an IP address. This controls the output of httprl_build_url_self()'),
18 $form['timeous'] = array(
19 '#type' => 'fieldset',
20 '#title' => t('Default Timeouts'),
21 '#collapsible' => TRUE
,
23 '#description' => t('Set the default timeouts. These will be overridden if a different timeout is set in the options array.'),
25 $form['timeous']['httprl_dns_timeout'] = array(
26 '#type' => 'textfield',
27 '#title' => t('dns_timeout. Maximum number of seconds a DNS lookup request may take'),
28 '#default_value' => variable_get('httprl_dns_timeout', HTTPRL_DNS_TIMEOUT
),
29 '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_DNS_TIMEOUT
)),
31 $form['timeous']['httprl_connect_timeout'] = array(
32 '#type' => 'textfield',
33 '#title' => t('connect_timeout. Maximum number of seconds establishing the TCP connection may take'),
34 '#default_value' => variable_get('httprl_connect_timeout', HTTPRL_CONNECT_TIMEOUT
),
35 '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_CONNECT_TIMEOUT
)),
37 $form['timeous']['httprl_ttfb_timeout'] = array(
38 '#type' => 'textfield',
39 '#title' => t('ttfb_timeout. Maximum number of seconds a connection may take to download the first byte'),
40 '#default_value' => variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT
),
41 '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_TTFB_TIMEOUT
)),
43 $form['timeous']['httprl_timeout'] = array(
44 '#type' => 'textfield',
45 '#title' => t('timeout. Maximum number of seconds the request may take'),
46 '#default_value' => variable_get('httprl_timeout', HTTPRL_TIMEOUT
),
47 '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_TIMEOUT
)),
49 $form['timeous']['httprl_global_timeout'] = array(
50 '#type' => 'textfield',
51 '#title' => t('global_timeout. Maximum number of seconds httprl_send_request() may take'),
52 '#default_value' => variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT
),
53 '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_GLOBAL_TIMEOUT
)),
57 return system_settings_form($form);
61 * Validate form values.
63 function httprl_admin_settings_form_validate($form, &$form_state) {
64 // Skip validation if we are resting to defaults.
65 if (isset($form_state['clicked_button']['#post']['op']) && $form_state['clicked_button']['#post']['op'] == 'Reset to defaults') {
70 $values = $form_state['values'];
72 // If the IP field is not blank, check that it is a valid address.
73 if ( !empty($values['httprl_server_addr'])
74 && $values['httprl_server_addr'] != -1
75 && ip2long($values['httprl_server_addr']) === FALSE
77 form_set_error('httprl_server_addr', t('Must be a valid IP address.'));
80 // Make sure the timeouts are positive numbers.
81 $positive_values = array(
83 'httprl_connect_timeout',
84 'httprl_ttfb_timeout',
86 'httprl_global_timeout',
88 foreach ($positive_values as
$name) {
89 if (empty($values[$name])) {
90 form_set_error($name, t('Must not be empty or zero.'));
93 if (!is_numeric($values[$name])) {
94 form_set_error($name, t('Must be numeric.'));
97 if ($values[$name] <= 0) {
98 form_set_error($name, t('Must be a postive number.'));