This module defines a (validated) postcode field for …

  • Form-API - This is mainly useful for developers.
  • A webform-component including form_builder support.

Dependencies

Usage of the form-API type

$form['postcode1'] = [
  '#type' => 'postcode',
  '#title' => t('UK Postcode'),
  // The postcode must be valid for the given country. (optional)
  // If no country is specified the "first" country where the value
  // is a valid postcode is assumed.
  '#postcode_country' => 'GB',
  // form-#parents of a form-field that is used to select the country. (optional)
  // Only evaluated if #postcode_country is empty.
  '#postcode_country_parents' => ['select', 'country'],
];
Supporting organizations: 
developed this module as part of campaignion.

Project information

Releases