You are here

function uc_addresses_get_address_form_validate in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.pages.inc \uc_addresses_get_address_form_validate()

Validate handler for the address form.

Checks if the address is similar to other addresses.

Return value

void

See also

uc_addresses_get_address_form()

uc_addresses_get_address_form_submit()

File

./uc_addresses.pages.inc, line 388
Page callbacks for viewing, adding, editing, and deleting addresses.

Code

function uc_addresses_get_address_form_validate($form, $form_state) {
  try {
    $address = $form['uc_addresses']['address']['#uc_addresses_address'];
    $address_book = UcAddressesAddressBook::get($address
      ->getUserId());

    // Check if the address looks like other addresses.
    if ($address_book
      ->compareAddress($address)) {
      if ($address
        ->isNew()) {
        form_set_error('uc_addresses][address', t('This address already appears in your address book. A new address was not added.'));
      }
      else {
        form_set_error('uc_addresses][address', t('The revised address is already in your address book. Your change was not made.'));
      }
    }
  } catch (Exception $e) {
    drupal_set_message($e
      ->getMessage(), 'error');
  }
}