You are here

function uc_addresses_get_address_form_validate in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 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 378
Page callbacks for viewing, adding, editing, and deleting addresses.

Code

function uc_addresses_get_address_form_validate(&$form, &$form_state) {
  switch ($form_state['clicked_button']['#value']) {
    case variable_get('uc_addresses_delete_button', t('Delete address')):

      // Don't do further validation.
      unset($form['uc_addresses']['address']['#element_validate']);
      unset($_SESSION['messages']['error']);
      $form_state['submitted'] = TRUE;
      form_set_error(NULL, '', TRUE);
      return;
  }

  // Check if the address looks like other addresses.
  try {
    $address = $form['uc_addresses']['address']['#uc_addresses_address'];
    $address_book = UcAddressesAddressBook::get($address
      ->getUserId());
    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');
  }
}