'textfield', '#title' => t('IP Address to send all self server requests to'), '#default_value' => variable_get('httprl_server_addr', FALSE), '#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()'), ); $form['timeous'] = array( '#type' => 'fieldset', '#title' => t('Default Timeouts'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('Set the default timeouts. These will be overridden if a different timeout is set in the options array.'), ); $form['timeous']['httprl_dns_timeout'] = array( '#type' => 'textfield', '#title' => t('dns_timeout. Maximum number of seconds a DNS lookup request may take'), '#default_value' => variable_get('httprl_dns_timeout', HTTPRL_DNS_TIMEOUT), '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_DNS_TIMEOUT)), ); $form['timeous']['httprl_connect_timeout'] = array( '#type' => 'textfield', '#title' => t('connect_timeout. Maximum number of seconds establishing the TCP connection may take'), '#default_value' => variable_get('httprl_connect_timeout', HTTPRL_CONNECT_TIMEOUT), '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_CONNECT_TIMEOUT)), ); $form['timeous']['httprl_ttfb_timeout'] = array( '#type' => 'textfield', '#title' => t('ttfb_timeout. Maximum number of seconds a connection may take to download the first byte'), '#default_value' => variable_get('httprl_ttfb_timeout', HTTPRL_TTFB_TIMEOUT), '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_TTFB_TIMEOUT)), ); $form['timeous']['httprl_timeout'] = array( '#type' => 'textfield', '#title' => t('timeout. Maximum number of seconds the request may take'), '#default_value' => variable_get('httprl_timeout', HTTPRL_TIMEOUT), '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_TIMEOUT)), ); $form['timeous']['httprl_global_timeout'] = array( '#type' => 'textfield', '#title' => t('global_timeout. Maximum number of seconds httprl_send_request() may take'), '#default_value' => variable_get('httprl_global_timeout', HTTPRL_GLOBAL_TIMEOUT), '#description' => t('Value can be a float. The default is %value seconds.', array('%value' => HTTPRL_GLOBAL_TIMEOUT)), ); return system_settings_form($form); } /** * Validate form values. */ function httprl_admin_settings_form_validate($form, &$form_state) { // Skip validation if we are resting to defaults. if (isset($form_state['clicked_button']['#post']['op']) && $form_state['clicked_button']['#post']['op'] == 'Reset to defaults') { return; } // Get form values. $values = $form_state['values']; // If the IP field is not blank, check that it is a valid address. if ( !empty($values['httprl_server_addr']) && $values['httprl_server_addr'] != -1 && ip2long($values['httprl_server_addr']) === FALSE ) { form_set_error('httprl_server_addr', t('Must be a valid IP address.')); } // Make sure the timeouts are positive numbers. $positive_values = array( 'httprl_dns_timeout', 'httprl_connect_timeout', 'httprl_ttfb_timeout', 'httprl_timeout', 'httprl_global_timeout', ); foreach ($positive_values as $name) { if (empty($values[$name])) { form_set_error($name, t('Must not be empty or zero.')); continue; } if (!is_numeric($values[$name])) { form_set_error($name, t('Must be numeric.')); continue; } if ($values[$name] <= 0) { form_set_error($name, t('Must be a postive number.')); continue; } } }