You are here

function uc_addresses_validate_address_field in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.module \uc_addresses_validate_address_field()

Validation handler for the uc_addresses_address form element.

Validates the uc_addresses_address form element and fills address object with values from the form.

Parameters

array $element: The form element to validate.

array $form_state: The complete form state.

Return value

void

See also

uc_addresses_element_info()

uc_addresses_process_address_field()

1 string reference to 'uc_addresses_validate_address_field'
uc_addresses_element_info in ./uc_addresses.module
Implements hook_element_info().

File

./uc_addresses.module, line 876
Adds user profile address support to Ubercart.

Code

function uc_addresses_validate_address_field(&$element, $form_state) {
  $handler_instances = uc_addresses_get_address_field_handler_instances($element['#uc_addresses_address'], $element['#uc_addresses_context']);
  $prefix = $element['#key_prefix'] ? $element['#key_prefix'] . '_' : '';
  foreach ($handler_instances as $fieldname => $instance) {
    if ($instance
      ->isFieldEnabled() && isset($element[$prefix . $fieldname])) {
      $instance
        ->validateValue($element[$prefix . $fieldname]['#value']);
    }
  }
  if (!form_get_errors()) {

    // Put form values into address object
    foreach ($handler_instances as $fieldname => $instance) {
      if ($instance
        ->isFieldEnabled() && isset($element[$prefix . $fieldname])) {
        $instance
          ->setValue($element[$prefix . $fieldname]['#value']);
      }
    }
  }
}