You are here

function commerce_ups_settings_form_validate in Commerce UPS 7.2

Same name and namespace in other branches
  1. 7 commerce_ups.admin.inc \commerce_ups_settings_form_validate()

Implements hook_form_validate().

File

includes/commerce_ups.admin.inc, line 238
Handles admin settings page for Commerce UPS module.

Code

function commerce_ups_settings_form_validate($form, &$form_state) {
  $values = $form_state['values'];

  // Ensure the default package size is less than the maximum
  // (http://www.ups.com/content/us/en/resources/prepare/oversize.html)
  //  Length (longest side) <= 108 inches
  //  Girth = 2*width + 2*height
  //  Length + Girth <= 165 inches.
  $dimensions = array(
    $values['commerce_ups_default_package_size_length'],
    $values['commerce_ups_default_package_size_width'],
    $values['commerce_ups_default_package_size_height'],
  );
  sort($dimensions);
  list($height, $width, $length) = $dimensions;
  $girth = 2 * $width + 2 * $height;
  if ($length > 108) {
    form_set_error('commerce_ups_default_package_size_length', t('The greatest dimension of the package size must be 108 inches or less.'));
  }
  if ($length + $girth > 165) {
    form_set_error('commerce_ups_default_package_size_length', t('The girth (2*width + 2*height) of the package size must be 165 inches or less.'));
  }
  $encrypted = variable_get('commerce_ups_encrypt', FALSE);

  // If the Password field is empty, then they're not trying to update it and we should ignore it.
  if (empty($values['commerce_ups_password'])) {
    unset($form_state['values']['commerce_ups_password']);
    if ($encrypted && empty($form_state['input']['commerce_ups_encrypt'])) {
      form_set_error('commerce_ups_password', t('You must enter in a password to turn off encryption.'));
    }
    return;
  }

  /* If we are setting or resetting values, test the connection.
    $ups_connection = ups_api_function_here();
    if (is_good_connection($ups_connection)) {
      drupal_set_message(t('Connection established. UPS credentials updated.'));
    }
    else {
      drupal_set_message(t('Resetting UPS credentials failed.'), 'error');
      form_set_error('commerce_ups_account_id', t('Unable to connect to UPS. Please check your credentials.'));
      form_set_error('commerce_ups_user_id');
      form_set_error('commerce_ups_access_key');
      form_set_error('commerce_ups_password');
    }
     */
}